7

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
  • I don't think you can do this using R code. The longtable LaTeX package supports it, but there's no way to request it using `knitr` or `kableExtra` functions. – user2554330 Sep 16 '17 at 11:50
  • 1
    Thanks @user2554330 for your comment. I got the required output in `R` using `xtable` ([See here](https://tex.stackexchange.com/a/220930/4821)). – MYaseen208 Sep 16 '17 at 13:53

1 Answers1

12

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:

jono3030
  • 412
  • 5
  • 14