I have the following issue, once knitting the Rmarkdown in Rstudio to PDF, my tables appear not in the position where they are in Rmarkdown file, but on the top of the page. I tried to add:
header-includes:
- usepackage{float}
and
```{r setup, include=FALSE}
knitr::opts_chunk$set(... fig.pos = "H")
```
But it didn't work. R and Rstudio run on Linux, the LaTeX engine is "pdflatex"
Fully reproducible example:
---
title: "Untitled"
output: pdf_document
header-includes:
- usepackage{float}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning = FALSE, fig.align = "center", dev = "cairo_pdf", fig.pos = "H")
```
```{r}
library(kableExtra)
library(tidyverse)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
ewpage
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
```{r}
kable(cars %>% filter(cars$speed>=23), caption = "Speed vs distance")
```
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…