rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
2.04k stars 209 forks source link

Repeating headers and/or column labels on multiple pages (LaTeX output) #1061

Open cswingle opened 2 years ago

cswingle commented 2 years ago

Proposal

When a table is converted to LaTeX the column labels are only printed on the first page of output. If the table extends onto subsequent pages, only the data rows are show. It would be handy to have an option to include headers and/or column labels at the top of each page. In the longtable environment, this is fairly simply done by adding \endhead at the end of what is considered the table header.

For example, here's a random table of numbers that spans two pages in LaTeX:

library(tidyverse)
library(gt)

random <- tibble(
  id = seq(1:50),
  random = runif(50)
)

t <- gt(random) %>%
  as_latex() %>%
  as.character()

The raw TeX (t) is:

\\begin{longtable}{rr}\n\\toprule\nid & random \\\\ \n\\midrule\n1 & 0.26041117 \\\\ \n2 & 0.78843314 \\\\ \n...

The top of the second page looks like this when the TeX is rendered to PDF:

image

If \\endhead\n is placed just after \\midrule\n in the raw output, the table will be rendered with the "id" and "random" headers on each page.

Like this:

image

I took a quick look at the code and it seems like this could be added to latex_heading_row and/or latex_group_row of R/utils_render_latex.R, but I'm not sure how options might get passed in here and there would be some additional logic to handle the placement of \endhead when there's both gt headers and column labels.

Maybe similar to #194

matthewt-assurity commented 4 months ago

Any updates on this? I've run into the exact same issue and this would be awesome to have!

olivroy commented 4 months ago

Relates to #1177, #1630

pedrohbraga commented 2 months ago

Hi! I just wanted to encourage the development of this feature! It is something that is missing for me, and that would make me shift from the other packages to gt.