Skip to content

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

Description

@cswingle

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions