I am trying to get a table in an Rmarkdown pdf to stay in the right place. I used kableExtra to make the table and it looks like this:
kable(site_info, "latex", caption = "Site Information", booktabs = T, align = "c") %>%
collapse_rows(columns = 1, latex_hline = "major", valign = "middle")%>%
kable_styling(latex_options = "hold_position")
It doesn't place the table where I want it, so I want to try the stronger option in the kableExtra documentation:
If you find hold_position is not powerful enough to literally PIN your table in the exact position, you may want to use HOLD_position, which is a more powerful version of this feature. For those who are familiar with LaTeX, hold_position uses [!h] and HOLD_position uses [H] and the float package.
I added the float package in my YAML, but how do I use the [H]?
For figures, I could use the knitr option fig.pos = "H"
, but this didn't work for the table.
Here is some example reproducible code of the problem. The table ends up at the top, just like in my real document:
---
title: "Put things in order"
author: "Ranae N. Dietzel"
header-includes:
- \usepackage{float}
output:
pdf_document: default
fig_caption: yes
---
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(tidyverse)
library(kableExtra)
ggplot(diamonds, aes(x=cut, y=price))+
geom_boxplot()
diamonds_summary<-diamonds%>%
group_by(cut)%>%
summarise(mean = mean(price))
kable(diamonds_summary, "latex", caption = "Price Summary", booktabs = T, align = "c") %>%
collapse_rows(columns = 1, latex_hline = "major", valign = "middle")%>%
kable_styling(latex_options = "HOLD_position")
ggplot(diamonds, aes(x=carat, y=price))+
geom_point()