【问题标题】:Produce a table spanning multiple pages using kable()使用 kable() 生成跨越多个页面的表
【发布时间】:2017-11-13 03:58:42
【问题描述】:

我想使用 kable() 生成一个跨越多个页面的表格。我知道使用带有“longtable”选项的 xtable() 可以做到这一点,但我需要 kable() 来获得其他功能。

有什么想法吗?

```{r cars, echo=TRUE, results='asis', warning=FALSE, message=FALSE}
    library(knitr)
    library(kableExtra)

# OUTPUT 1, fits on one page
output = rbind(mtcars[, 1:5])

kable(output, booktabs = T, format="latex", caption = "Small Output")


# OUTPUT 2, will not fit on one page 
output = rbind(mtcars[, 1:5], mtcars[, 1:5])

kable(output, booktabs = T, format="latex", caption = "Large Output")

```

更新:我很笨! “longtable=TRUE”是一个选项。问题是这改变了我的输出顺序并且有点搞砸了。

【问题讨论】:

    标签: r r-markdown knitr


    【解决方案1】:

    您可以尝试使用 kableExtra 包。如果您在kable_styling 中指定hold_position,您应该能够将表ping 到您想要的位置。

    另外,在当前的开发版本中,我为longtable 引入了一个名为repeat_header 的新功能,可以在每一页上重复标题行。你可以检查一下。

    kable(output, "latex", booktabs = TRUE, longtable = TRUE, caption = "Test") %>%
      kable_styling(latex_options = c("hold_position", "repeat_header"))
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-10
    • 2013-08-07
    • 1970-01-01
    • 2017-11-09
    • 2011-04-26
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    相关资源
    最近更新 更多