我正在使用 rmarkdown 输出 PDF 文档,但是向绘图添加标题似乎不起作用。根据文档,我们应该使用fig.cap指定要传递给 Latex 的图形标题。这是我的代码块的标题:
```{r Plot bond index returns, include = TRUE, fig.cap = "Bond index cumulative returns"}
Run Code Online (Sandbox Code Playgroud)
我确保在 rmarkdown 文档的标题中包含以下几行
output:
pdf_document:
fig_caption: true
此设置完全消除了生成的 PDF 中的整个块的输出
您能提供更多细节吗?我无法重现这个错误。准系统 .Rmd 看起来像:
---
output: pdf_document
---
```{r echo = FALSE, fig.cap = "Test figure caption."}
plot(pressure)
```
Run Code Online (Sandbox Code Playgroud)
我得到如下输出:
编辑:
查看此问题的答案后,以下代码生成图形,其中文本散布在图形中:
---
output: pdf_document
header-includes:
\usepackage{float}
\floatplacement{figure}{H}
---
```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.pos = 'h')
```
Here is text number preceding figure 1
```{r echo = FALSE, fig.cap = "Test figure caption."}
plot(pressure)
```
Here is text following figure 1
```{r echo = FALSE, fig.cap = "Second test figure caption."}
plot(cars)
```
Here is some final text following the second figure
Run Code Online (Sandbox Code Playgroud)