kableExtra: Continued on Next Page for longtable

6.6k views Asked by At

I am using kableExtra for longtable with the following code.

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"))

The output is

enter image description here

I wonder how to add text (Continued on Next Page ...) at the bottom of the table if it spans to next page.

1

There are 1 answers

0
jono3030 On BEST ANSWER

There is a kableExtra argument for that. I haven't checked but I suppose it wasn't available when the question was first posted.

From the documentation:

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.

The default is (continued...) so for your specific case it would be:

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...)}")

Output: