Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce title margins when creating PDF from Rmarkdown using knitr

I'm creating a PDF document using knitr + Rmarkdown. I've set geometry: margin=0.1in in the yaml header. This margin applies to the body text of the document, but the title is quite far from the top of the document, as well as the body text. Here's a screenshot:

enter image description here

Here's the Rmd code that created the document in the screenshot:

---
title: "test"
output: 
  pdf_document:
    latex_engine: xelatex
geometry: margin=0.1in
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

a bunch of text to demonstrate that the margin applies only to the body text of
this document, while the title (above) remains quite far from the top of the
document, and this is messing up my plan to make a document that's only one page
in length

I need this document to be one page in length. The title's huge margins are messing that up. How can I reduce the whitespace between the title, the top of the document, and the body text?

Note: For reasons, I can only use the xelatex latex engine here.

like image 448
ardaar Avatar asked Sep 18 '25 19:09

ardaar


1 Answers

Using LaTeX code, you can:

  • reduce the space between the title and the text with \vspace{-1cm}

  • reduce the top margin with the same code placed in title in the YAML

Here's your example:

---
title: \vspace{-1.5cm} test
output: 
  pdf_document:
  latex_engine: xelatex
geometry: margin = 0.1in
---

\vspace{-1cm}
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

a bunch of text to demonstrate that the margin applies only to the body text of
this document, while the title (above) remains quite far from the top of the
document, and this is messing up my plan to make a document that's only one page in length
like image 65
bretauv Avatar answered Sep 21 '25 17:09

bretauv