调整R Markdown PDF文档中文本和块输出之间的间距 [英] Adjust spacing between text and chunk output in a R Markdown PDF document

查看:42
本文介绍了调整R Markdown PDF文档中文本和块输出之间的间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解如何控制R Markdown PDF文档中文本和块输出之间的间距时遇到了麻烦.下面是一个文档示例:

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
```

删除文本"Random Text"和块输出之间的空间的最佳方法是什么,以便"Random Text"与图表的黑色边框齐平.

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.

第二,如果我想在随机文本"和图表的黑色边框之间留出1厘米的距离,怎么办?

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

谢谢

推荐答案

不确定为什么要这样做,但是可以在本地更改 \ parskip :

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

这篇关于调整R Markdown PDF文档中文本和块输出之间的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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