简体   繁体   English

调整R Markdown PDF文档中文本和块输出之间的间距

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

I'm having trouble understanding how to control spacing between the text and chunk output in a R Markdown PDF document. 我在理解如何控制R Markdown PDF文档中文本和块输出之间的间距时遇到了麻烦。 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. 删除文本“ Random Text”和块输出之间的空间的最佳方法是什么,以便“ Random Text”与图表的黑色边框齐平放置。

Secondly, if I wanted space of 1cm between "Random Text" and the black border of the chart how would I do that? 其次,如果我想在“随机文本”和图表的黑色边框之间留出1厘米的距离,我该怎么做?

Thanks 谢谢

Not sure why you would want this, but you can locally change \\parskip : 不知道为什么要这么做,但是可以在本地更改\\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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM