Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 249
Dambo Avatar asked Oct 17 '22 07:10

Dambo


1 Answers

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.

like image 120
Nathan Werth Avatar answered Oct 20 '22 23:10

Nathan Werth