【发布时间】:2018-11-05 11:30:28
【问题描述】:
我有以下问题,将 Rstudio 中的 Rmarkdown 编织为 PDF 后,我的表格不会出现在 Rmarkdown 文件中的位置,而是出现在页面顶部。我尝试添加:
header-includes:
- \usepackage{float}
和
```{r setup, include=FALSE}
knitr::opts_chunk$set(... fig.pos = "H")
```
但它没有用。 R和Rstudio在Linux上运行,LaTeX引擎是“pdflatex”
完全可重现的示例:
---
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>.
\newpage
## 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")
```
【问题讨论】:
-
似乎图形环境仅在您使用
fig.cap定义标题时才添加。那么定位参数应该按预期使用。 -
解决方法是,删除
kable ()中的caption="...",一旦删除,定位就开始起作用了。
标签: r r-markdown kable