Longtable in a Knitr (Pdf) Document: Using Xtable (Or Kable)

kableExtra: Continued on Next Page for longtable

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:

Sample Image

Produce a table spanning multiple pages using kable()

You can try to use the kableExtra package. If you specify hold_position in kable_styling, you should be able to ping the table to the place you want.

Also, in the current dev version, I introduced a new feature called repeat_header for longtable to repeat the header row on every page. You can check it out.

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

xTable Knitr Error - every line is printed underneath in PDF

If you want to knit in a pdf keep results='asis' and don't print xtable.

```{r echo=FALSE}
library(xtable)
swisstable <- sapply(swiss,function(x) {
c(Mean = mean(x), SD = sd(x), Median = median(x), IQR = IQR(x))
})
```

```{r results='asis', echo=FALSE}
xtable(swisstable, digits = 1, caption = "Tabelle 2: Überblick über den Datensatz swiss")
```

Sample Image



Related Topics



Leave a reply



Submit