简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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