在Rmarkdown中显示长表

在Rmarkdown中显示长表,r,r-markdown,kableextra,R,R Markdown,Kableextra,有没有一种方法可以在rmarkdownPDF输出中很好地显示包含许多列的表?正在寻找一些包装器选项,以将其显示为3个连续的表,但不将数据帧拆分为3个单独的帧。这是我的一块,使桌子很小,几乎看不清 library(knitr) library(readr) library(kableExtra) dat_url <- 'https://gender-pay-gap.service.gov.uk/viewing/download-data/2019' dat <- read_csv(da

有没有一种方法可以在
rmarkdown
PDF输出中很好地显示包含许多列的表?正在寻找一些包装器选项,以将其显示为3个连续的表,但不将数据帧拆分为3个单独的帧。这是我的一块,使桌子很小,几乎看不清

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'))
库(knitr)
图书馆(readr)
图书馆(kableExtra)

dat_url我不知道如何使用
kable
。我更喜欢使用
xtable
和LaTeX代码

library(xtable)
print(xtable::xtable(dat[1:30,c(1,3)], align="ll|c"), 
      hline.after = F,
      include.rownames=F, 
      include.colnames = F,
      tabular.environment = 'longtable',
      caption.width = "8.5in",
      comment=F,
      floating = F,
      add.to.row = list(pos = list(0),
                        command =
                          paste("\\caption{ZzZzZzZz} \n \\label{tab:tb1} \n \\\\ \\hline \\hline \n",
                                " \\textbf{Employer Name} & \\textbf{Sic Codes}\\\\ \\hline \n",  
                      "\\endhead \n", 
                                " \\multicolumn{2}{r}{\\footnotesize \\emph{Continued on next page...}} \n \\\\                    
                                 \\endfoot \\hline \\hline
                                 \\endlastfoot \n",collapse=" ")))
代码有点长,但应该可以工作


为了它的价值,我将
dat
分为3部分,并将
kable
d全部分开:

 kable(head(dat[,1:7]), caption='Original Data: first 6 rows', booktabs=TRUE, linesep="")  %>%
  kable_styling(latex_options =c('striped', 'scale_down', 'hold_position'))

  kable(head(dat[,8:18]), booktabs=TRUE, linesep="")  %>%
  kable_styling(latex_options =c('striped', 'scale_down', 'hold_position'))
  
  kable(head(dat[,19:22]), booktabs=TRUE, linesep="")  %>%
  kable_styling(latex_options =c('striped', 'scale_down', 'hold_position'))

@Werner-我通过YAML标题将其保存为
output:pdf\u document