Skip to content

fix: ensure that cells_stub() works with LaTeX output tables#2104

Merged
rich-iannone merged 3 commits intomasterfrom
fix-cells-stub-align-latex
Jan 14, 2026
Merged

fix: ensure that cells_stub() works with LaTeX output tables#2104
rich-iannone merged 3 commits intomasterfrom
fix-cells-stub-align-latex

Conversation

@rich-iannone
Copy link
Copy Markdown
Member

This PR fixes the use of cells_stub() for LaTeX output tables. We can now properly target all stub columns when columns = NULL for multi-column stubs. This ensures that styles and footnotes are applied to every stub column rather than just the first one.

This gt code:

exibble[, c(1, 2, 8, 9)] |>
  gt(
    rowname_col = c("group", "char")
  )|>
  tab_style(
    style = list(
      cell_text(align = "right")
    ),
    locations = list(cells_stub()) 
  ) |>
  as_latex() |>
  cat()

Now produces this LaTeX output:

\begin{table}[t]
\fontsize{12.0pt}{14.0pt}\selectfont
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}l|l|rl}
\toprule
\multicolumn{2}{c}{} & num & row \\ 
\midrule\addlinespace[2.5pt]
\multicolumn{1}{r}{{grp\_a}} & \multicolumn{1}{r}{{apricot}} & 1.111e-01 & row\_1 \\ 
\multicolumn{1}{r}{{}} & \multicolumn{1}{r}{{banana}} & 2.222e+00 & row\_2 \\ 
\multicolumn{1}{r}{{}} & \multicolumn{1}{r}{{coconut}} & 3.333e+01 & row\_3 \\ 
\multicolumn{1}{r}{{}} & \multicolumn{1}{r}{{durian}} & 4.444e+02 & row\_4 \\ 
\multicolumn{1}{r}{{grp\_b}} & \multicolumn{1}{r}{{NA}} & 5.550e+03 & row\_5 \\ 
\multicolumn{1}{r}{{}} & \multicolumn{1}{r}{{fig}} & NA & row\_6 \\ 
\multicolumn{1}{r}{{}} & \multicolumn{1}{r}{{grapefruit}} & 7.770e+05 & row\_7 \\ 
\multicolumn{1}{r}{{}} & \multicolumn{1}{r}{{honeydew}} & 8.880e+06 & row\_8 \\ 
\bottomrule
\end{tabular*}
\end{table}

Notice the use of the \multicolumn{1}{r}{{...}} in the first two columns (this is a two-column stub).

Fixes: #2103

@thebioengineer
Copy link
Copy Markdown
Collaborator

I just opened #2105 🤣

@rich-iannone
Copy link
Copy Markdown
Member Author

@thebioengineer you are awesome! Yeah, the gt package is getting a lot of (overdue) attention today :)

@rich-iannone rich-iannone merged commit 336a5f9 into master Jan 14, 2026
12 checks passed
@rich-iannone rich-iannone deleted the fix-cells-stub-align-latex branch January 14, 2026 22:04
@rich-iannone
Copy link
Copy Markdown
Member Author

I don't think I've ever had a situation like this but @thebioengineer , could you close #2105? This PR is now merged. I'll definitely review your #2101 PR though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alignment of stub columns doesn't work in LaTeX

2 participants