在RMarkdown中的图形周围添加空间 [英] Adding space around figures in RMarkdown

查看:102
本文介绍了在RMarkdown中的图形周围添加空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在RMarkdown中的图形周围添加空格.我正在编织PDF,真的不喜欢数字(或方程式)与文本或下一个数字的距离如此之近.

I would like to add space around figures in RMarkdown. I am knitting to PDF and really don't like how close figures (or also equations) are to the text or to the next figure.

---
output: pdf_document
---

```{r pressure, echo=FALSE}
plot(pressure)
```

```{r pressure2, echo=FALSE}
plot(pressure)
```

两个图之间的空间太小,使用ggplots时变得更加模糊.

There is just too little space between the two plots and this gets more fuzzy when using ggplots.

现在我使用乳胶溶液

\vspace{10pt}

但是,如果我可以为整个文档进行全局设置,那就太好了.

but it would be nice if I could make a setting globally for the entire document.

推荐答案

关于绘图前后的间距,您可以使用简单的编织钩子:

Concerning the spacing before and after plots you can use a simple knitr hook:

```{r, echo = F}
library(knitr)
if(is_latex_output()) {
  plot_default <- knit_hooks$get("plot")
  knit_hooks$set(plot = function(x, options) { 
    x <- c(plot_default(x, options), "\\vspace{25pt}")
  })
}
```

在这种情况下,我们改变了绘图钩子,即在每个绘图输出之后仅添加了25pt的间距.

Here we alter the plot hook in that sense that we just add a spacing of 25pt after each plot output.

关于方程式,您只需在文档开头添加以下四个长度定义:

Concerning equations you can just add these four length definitions at the beginning of your document:

\setlength{\abovedisplayskip}{25pt}
\setlength{\belowdisplayskip}{25pt}
\setlength{\abovedisplayshortskip}{25pt}
\setlength{\belowdisplayshortskip}{25pt}

使用align环境创建的前两个Alternate方程.后两个是使用$$ ... $$创建的.

The first two alter equations created using the align environment. The latter two those created using $$ ... $$.

这篇关于在RMarkdown中的图形周围添加空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆