Home > Enterprise >  R Markdown, kable_styling(latex_options="HOLD_position") not working
R Markdown, kable_styling(latex_options="HOLD_position") not working

Time:11-24

I have a problem that I've seen several times on here, but the usual solutions aren't working. I can't share all of my code due to some PHI concerns, but I'll try to share as much as I can.

The problem

My kable tables are showing up below the respective headers.

Example code: enter image description here

Example output: enter image description here

What I've tried

So there are already a few answers on here about similar problems, like enter image description here

So when I added some random text prior to the tables that weren't showing up in the right spot, they did show up correctly. (Pictured below) Problem is, I don't want to have to add text there. enter image description here enter image description here

CodePudding user response:

Ok, let's solve it with the pure LaTeX ;)

---
title: "Test Table"
date: '2021-11-11'

header-includes: 
- \usepackage{float}
- \usepackage{caption}

output:
  pdf_document
---

```{r}
library(kableExtra)
tab1<- head(mtcars) %>% kbl()
```

\begin{table}[H]
\captionof{table}{Table, stay here!}
`r tab1`
\end{table}

enter image description here

  • Related