Search code examples
rr-markdownkableextra

Display long table in Rmarkdown


Is there a way to display a table with many columns nicely in rmarkdown PDF output? looking for some wrapper option to display it as say 3 consecutive tables but without breaking the data frame into 3 separate frames. Here is my chunk that makes the table very small and barely legible.

library(knitr)
library(readr)
library(kableExtra)
dat_url <- 'https://gender-pay-gap.service.gov.uk/viewing/download-data/2019'
dat <- read_csv(dat_url) 
kable(head(dat), caption='Sample Data: 6 rows', booktabs=TRUE, linesep="")  %>%
kable_styling(latex_options =c('striped', 'scale_down'))

Solution

  • 'longtable = true' in kable to split table across pages, "repeat_header" to, you guessed it..

    x_df %>% 
       kbl(caption = "caption", 
        align = "l",
        format = "latex",
        centering = FALSE,
        booktabs = TRUE,
        longtable = TRUE,
        linesep = "") %>% 
       kable_styling(bootstrap_options = c("striped", "hover"), position = "left", full_width = F, fixed_thead = T, latex_options = c("striped", "HOLD_position", "repeat_header"))