【发布时间】:2015-06-24 03:01:25
【问题描述】:
我正在使用 knitr(1.9.5 和 1.9.17)和 rmarkdown(0.5.3.1),并希望在 pdf 输出中保持图形位置。当使用块选项fig.pos="H" 时,生成的 pdf 文件工作正常。
但是,当fig_caption: yes 设置在
yaml 头文件。
我应该如何解决这个问题?感谢您的任何建议。
编辑:
学习了Latex的浮动环境。我将float 包添加到标题中。
\usepackage{float}
但是在figure 环境中生成的tex 文件总是使用htbp,而对于使用任何fig.pos 选项。手动将htbp更改为H后,所有人物的位置都保持不变。
这是我的 rmd 文件示例:
---
title: "Untitled"
output:
pdf_document:
fig_caption: yes
includes:
in_header: mystyles.sty
---
# Section 1
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
```{r fig1, echo=FALSE, fig.height=8.5, fig.pos="H"}
plot(cars)
```
# Section 2
More test
```{r fig2, echo=FALSE, fig.height=8.5, fig.pos="H"}
plot(cars)
```
# Section 3
```{r fig3, echo=FALSE, fig.height=8.5, fig.pos="H"}
plot(cars)
```
More test
【问题讨论】:
-
我在这里找到了易辉的答案,可能回答了我的问题:stackoverflow.com/questions/16626462/…
-
我也遇到过类似的问题。我假设 fig.pos 实际上并没有从 .Rmd 解析到 Pandoc,因为在检查 .tex 输出时,它只列出了您的图的 4 个选项 [htpb]。
-
@kristang,正如 Yihui 在他的回答中提到的,我们不能对 Markdown 的格式有太多期望。只需编写一些 R 脚本将 htpb 替换为 H。将发布我的脚本。
-
当然。我只是觉得很奇怪,当它没有被解析时它被列为一个选项。
标签: r knitr r-markdown