Adjust spacing between text and chunk output in a R Markdown PDF document

梦想与她 提交于 2019-12-11 05:15:40

问题


I'm having trouble understanding how to control spacing between the text and chunk output in a R Markdown PDF document. Below is an example of a document:

---
output: pdf_document

---
\setlength\lineskip{0pt}
\begin{center}
Random Text
\end{center}

```{r echo = FALSE, message=FALSE}
library(tidyverse)
p1 <- ggplot(mtcars, aes(x = row.names(mtcars), mpg)) +
        geom_bar(stat = "identity") +
        theme(panel.border = element_rect(colour = "black", fill=NA, size=1),
              plot.margin=grid::unit(c(0,0,0,0), "mm")) +
              coord_flip()

p1
```

What is the best approach to remove the space between the text "Random Text" and the chunk output so "Random Text" sits flush with the black border of the chart.

Secondly, if I wanted space of 1cm between "Random Text" and the black border of the chart how would I do that?

Thanks


回答1:


Not sure why you would want this, but you can locally change \parskip:

\begingroup
\parskip=0pt
\begin{center}
Random Text
\end{center}

```{r echo = FALSE, message=FALSE}
library(tidyverse)
p1 <- ggplot(mtcars, aes(x = row.names(mtcars), mpg)) +
        geom_bar(stat = "identity") +
        theme(panel.border = element_rect(colour = "black", fill=NA, size=1),
              plot.margin=grid::unit(c(0,0,0,0), "mm")) +
              coord_flip()

p1
```
\endgroup


来源:https://stackoverflow.com/questions/56130565/adjust-spacing-between-text-and-chunk-output-in-a-r-markdown-pdf-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!