paulr
paulr

Reputation: 85

RMarkdown. How to reduce space between title block and start of body text

I've been using RMarkdown via RStudio on a Mac successfully.

Recently upgraded to RStudio 1.2.5019 and tinytex_0.18 and now the vertical spaceing between my "title block" and "first body text / heading" has increased.

Simple example, (deliberately excluding author: and date:), is:

---
output: 
  pdf_document
title: "Example of Title to Body Text"
subtitle: Subtitle Places Here
---
This is the first paragraph (or heading if specified as such). It is quite a way down from the title of the document. How can this be reduced to a "single line" vertical space?

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.

I then tried to use the "titlesec" package, but haven't been able to work out which command to use to achieve the desired outcome. Example of attempt is:

---
output: 
  pdf_document

subparagraph: yes
header-includes: |
  \usepackage{titlesec}
  \titlespacing{\title}{0pt}{\parskip}{-\parskip}

title: "Example of Title to Body Text"
subtitle: Subtitle Places Here
---
This is the first paragraph (or heading if specified as such). It is quite a way down from the title of the document. How can this be reduced to a "single line" vertical space?

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.

This is what it currently looks like rendered to PDF.

Current output

This is what I would like the PDF to look more like (edit from graphics program).

Desired output

So, how can I reduce this vertical spacing between the title block and the start of the document's body?

Thanks in advance.

Upvotes: 7

Views: 22126

Answers (2)

Hongtao Hao
Hongtao Hao

Reputation: 83

For others who are also trying to move both the title and body text upward:

I do not understand what the two lines that paulr shared are doing:

\usepackage{titlesec}
\titlespacing{\title}{0pt}{\parskip}{-\parskip}

But I found another solution here, which uses the package of titling, and then moves the title up by \setlength{\droptitle}{5em}.

After title is done, you can move the body text up using carlos's answer.

Upvotes: 3

Carlos Luis Rivera
Carlos Luis Rivera

Reputation: 3663

You can reduce the space between the (sub)title and the first paragraph by adding \vspace{} command from LaTeX right before the first paragraph.

---
output: 
  pdf_document

subparagraph: yes
header-includes: |
  \usepackage{titlesec}
  \titlespacing{\title}{0pt}{\parskip}{-\parskip}

title: "Example of Title to Body Text"
subtitle: Subtitle Places Here
---

\vspace{-5truemm}


This is the first paragraph (or heading if specified as such). It is quite a way down from the title of the document. How can this be reduced to a "single line" vertical space?

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.

Upvotes: 13

Related Questions