我正在尝试使用knitr和pandoc转换为PDF时控制绘图的位置.我的.Rmd文件看起来像这样:
# My report
Some text some text some text some text some text some text some text some text some text
```{r myplot, echo=FALSE, fig.pos="placeHere", results='hide'}
library(ggplot2)
ggplot(mtcars, aes(mpg, drat)) + geom_point()
```
Some text some text some text some text some text some text some text some text some text
\usepackage{graphicx}
\begin{figure}[placeHere]
\centering
\includegraphics[width=0.5\textwidth]{placeHere}
\end{figure}
Some text some text some text some text some text some text some text some text some text
Run Code Online (Sandbox Code Playgroud)
我正在使用此处提供的功能转换为PDF:http://quantifyingmemory.blogspot.co.uk/2013/02/reproducible-research-with-r-knitr.html
如何在第二和第三块文本之间放置图?乳胶代码目前无法正常工作. …
我对R Markdown有些新意,所以如果这很愚蠢,请道歉.我正在准备一个使用R Markdown/Knitr的pdf报告,并遇到一个问题,如果我尝试使用kable包含一个样式表,它会将表移动到页面底部.
以下是代码示例:
---
title: "Testing"
output:
pdf_document:
fig_caption: yes
tables: true
---
```{r setup, include=FALSE}
library(knitr)
library(kableExtra)
```
Section 1: In Table \ref{fig:table1} below...
```{r table1, echo=FALSE}
kable(head(mtcars[,1:4],4), format = "latex", align = "c", caption ="\\label{fig:table1}Table Caption") %>%
column_spec(1, bold = T, width = "6em") %>%
kable_styling(position = "center")
```
Section 2: Lorem ipsum dolor sit amet
Run Code Online (Sandbox Code Playgroud)
这个输出的PDF有"第1部分"和"第2部分"相互跟随,表格位于页面的最底部. 
我已经尝试删除标题,并在块的开头使用fig.cap.虽然我的表保持在应有的位置,但它根本不会生成标题,并且对该图的引用变为?? .
什么有效:摆脱kableExtra,将格式从latex更改为pandoc.该表保留在应有的位置,并且我得到了标题,但是表格丢失了我真正想要的报告格式.
我究竟做错了什么?谢谢你的帮助!
编辑:对不起!我希望桌子显示我放在哪里(在"第1节"之后,在"第2节"之前).如下所示,仅带有标题/图形标签.(链接的图像是我得到的,如果我摆脱上面的代码块中的标题arg)
