RMarkdown:Space 在 LaTeX 输出中浮点代码的位置

RMarkdown: Space in LaTeX output at place of code for float

当在 RMarkdown 中的两个段落之间包含图形代码时,代码产生的浮点数可能会放置在文档的不同位置,从而在 LaTeX/PDF 中的段落之间留下 space输出文件。

以下最小示例说明了该问题:

---
output: pdf_document
---

This is my first paragraph. 
Next in the Rmd file would be the code for the figure.  
The figure is correctly treated as a float by LaTeX, meaning that LaTeX will put it to the next suitable position.
```{r pressure, echo=FALSE, fig.cap="Example", out.width='0.5\textwidth', fig.pos='B'}
  plot(pressure)
```
The problem now is, that this leaves space to my second paragraph.
Usually, this should not be the case.
In pure LaTeX, there is a linebreak, of course, but no vertical space in addition.

如果您将 \vspace{-\parsep} 放在以下文本的开头,您将得到没有额外 space 的换行符。也就是说,

---
output: pdf_document
---

This is my first paragraph. 
Next in the Rmd file would be the code for the figure. 
The figure is correctly treated as a float by LaTeX, meaning that LaTeX will put it to the next suitable position.
```{r pressure, echo=FALSE, fig.cap="Example", out.width='0.5\textwidth', fig.pos='B'}
  plot(pressure)
```
\vspace{-\parsep}The problem is now fixed.

我没有看到任何其他方法可以做到这一点:knitr 在生成 LaTeX 时在 figure 环境周围放置空行。