Adding space around shapes in RMarkdown

I would like to add space around the shapes in RMarkdown. I am knitting in PDF and really do not like how close numbers (or equations) relate to the text or to the next drawing.

---
output: pdf_document
---

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

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

There is too little space between the two charts and this becomes more fuzzy when using ggplots.

I am now using the Latex solution

\vspace{10pt}

but it would be nice if I could do the setting all over the world for the entire document.

+1
source share
1 answer

As for the intervals before and after the charts, you can use a simple knife 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}")
  })
}
```

Here we change the plot hook in the sense that we simply add an interval 25ptafter each plot output.

:

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

, align. , $$ ... $$.

+2

Source: https://habr.com/ru/post/1692368/


All Articles