When I use a knitr::kable
in a latex doc, the table floats. How do I stop it from floating?
Asked
Active
Viewed 3,434 times
2

dfrankow
- 20,191
- 41
- 152
- 214
-
1have you read the advice in the bookdown book? https://bookdown.org/yihui/bookdown/tables.html This uses the argument ? longtable = T` and the Latex-command `\usepackage{longtable}` – J_F Mar 13 '17 at 13:07
-
Sweet! If you submit this as an answer, I'll accept. – dfrankow Mar 13 '17 at 14:42
1 Answers
9
Use the argument longtable = T
in knitr::kable()
and add \ usepackage{longtable}
in the YAML header:
---
title: "Using longtable in RMD"
output: pdf_document
date: "`r format(Sys.time(), '%d %B %Y')`"
author: Author
header-includes:
- \usepackage{longtable}
---
```{r}
knitr::kable(cars, longtable = T)
```

Josh O'Brien
- 159,210
- 26
- 366
- 455

J_F
- 9,956
- 2
- 31
- 55
-
I'm actually using LaTeX knitr, not markdown, so that \usepackage is not in a YAML header. Also, I say longtable=TRUE, not longtable=T. But, I'll accept this, why not. – dfrankow Mar 13 '17 at 15:25
-
1Also kableExtra solution here: https://stackoverflow.com/questions/44850011/how-to-stop-bookdown-tables-from-floating-to-bottom-of-the-page-in-pdf – puslet88 May 27 '19 at 16:38