我正在尝试在RMarkdown文档中插入图形,但无法将其显示在正确的位置。下图显示了该问题:使用图标题时,该图显示在页面顶部而不是文档中相关段落的下面。
这是此最小工作示例的代码:
---
title: "Untitled"
author: "Author"
date: "27 February 2017"
output:
pdf_document:
fig_cap: yes
keep_tex: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.pos= "h")
```
## 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, fig.cap = "Hello"}
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.
这是LaTeX输出的相关部分;请注意,
fig.pos
选项将被忽略:You can also embed plots, for example:
\begin{figure}
\centering
\includegraphics{test_files/figure-latex/pressure-1.pdf}
\caption{Hello}
\end{figure}
Note that the \texttt{echo\ =\ FALSE} parameter was added to the code
chunk to prevent printing of the R code that generated the plot.
我的设置如下所述。我很确定这在knitr的早期版本中有效,但是我没有记下可能是哪个版本。
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] backports_1.0.5 magrittr_1.5 rprojroot_1.2 htmltools_0.3.5 tools_3.3.2
[6] yaml_2.1.14 Rcpp_0.12.9 stringi_1.1.2 rmarkdown_1.3 knitr_1.15.1
[11] stringr_1.2.0 digest_0.6.12 evaluate_0.10
最佳答案
块选项fig.pos
仅在 knitr 认为必须写出LaTeX figure
环境而非纯Markdown ![]()
时才使用,并且仅当指定了图形标题(fig.cap
)且至少其中一个具有已指定:fig.align
,out.width
,out.extra
。如果要强制编织程序编写图形的LaTeX代码并使用fig.pos
,则可以设置块选项out.extra = ''
。
关于r - 编织者忽略了fig.pos?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42486617/