kableExtra:在下一页继续 longtable

kableExtra: Continued on Next Page for longtable

我将 kableExtra 用于 longtable,代码如下。

library(knitr)
library(kableExtra)

long_dt <- rbind(mtcars, mtcars)

kable(
      long_dt, 
      format    = "latex", 
      longtable = T, 
      booktabs  = T, 
      caption   = "Longtable"
      ) %>%
add_header_above(c(" ", "Group 1" = 5, "Group 2" = 6)) %>%
kable_styling(latex_options = c("repeat_header"))

输出为

我想知道如何在 table 的底部添加文本 (接下页 ...) 如果它跨越到下一页。

对此有一个 kableExtra 参数。我没有检查过,但我想当问题第一次发布时它不可用。

来自文档:

repeat_header_continued: T/F or a text string. Whether or not to put a continued mark on the second page of longtable. If you put in text, we will use this text as the "continued" mark.

默认值为 (续...) 因此对于您的特定情况,它将是:

library(knitr)
library(kableExtra)

long_dt <- rbind(mtcars, mtcars)

kable(
      long_dt, 
      format    = "latex", 
      longtable = T, 
      booktabs  = T, 
      caption   = "Longtable"
      ) %>%
add_header_above(c(" ", "Group 1" = 5, "Group 2" = 6)) %>%
kable_styling(latex_options = c("repeat_header"),
              repeat_header_continued = "\textit{(Continued on Next Page...)}")

输出: