r - 编织者忽略了fig.pos?

标签 r knitr r-markdown figure

我正在尝试在RMarkdown文档中插入图形,但无法将其显示在正确的位置。下图显示了该问题:使用图标题时,该图显示在页面顶部而不是文档中相关段落的下面。

enter image description here

这是此最小工作示例的代码:

---
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.alignout.widthout.extra。如果要强制编织程序编写图形的LaTeX代码并使用fig.pos,则可以设置块选项out.extra = ''

关于r - 编织者忽略了fig.pos?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42486617/

相关文章:

python - 具有缺失值的分类数据中的降维

r - 在 knitr 中跨 block 传递图形参数

r - 用 knitr markdown 并排的两个 block

r - 使用 knitr 和 kableExtra 的脚注中的公式或符号

r - html Rmarkdown中上图的标题

html - 如何在 Jekyll post 中包含 Rmarkdown/HTML 文件

r - 如何从 R/shiny 中的传单 map 获取缩放级别?

与 GGally 对图的圆形相关

r - 通缉 : repeated-pictogram visualization of population split

r - 使用 RStudio : why reading . RProfile 编译 RMarkdown?