Dambo
Dambo

Reputation: 3486

How to prevent a kable from splitting between pages?

I am knitting to pdf using kable() to draw some tables. I create a few tables functionally, thus some of them end up being split between pages. Is there any way to prevent this behavior?

I know I could just move to a new page after each table but I would much rather have multiple kables on the same page.

Upvotes: 8

Views: 2985

Answers (1)

Nathan Werth
Nathan Werth

Reputation: 5263

If you're only exporting to PDF, then try this:

knitr::kable(
  my_data,
  format    = "latex",
  longtable = FALSE
)

A longtable table allows page breaks between rows. Looking at the code for knitr:::kable_latex, which kable calls, the default should be longtable = FALSE. But explicitly setting this argument makes sure you're not making longtables.

Upvotes: 5

Related Questions