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

2

6

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.

Meagre answered 8/1, 2020 at 7:4 Comment(0)
V
12

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.
Vassalize answered 10/1, 2020 at 14:15 Comment(2)
Just wanted to say thanks! This has worked just as I needed.Meagre
Happy to hear your success! Well,don't forget to upvote, too, hahahaVassalize
P
2

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 \setlengh{\droptitle}{5em}.

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

Phthisis answered 2/12, 2020 at 20:19 Comment(2)
@Meagre tried to reduce the space between title of an article and the contents by applying titlesec package. However, the command \titlespacing{\title}{0pt}{\parskip}{-\parskip} is in vain because the package does not support the spacing handling of the title of the article. The package only deals with the spacing around the \section, \subsection... and so on.Vassalize
In case confusing to anyone why they are getting "undefined control sequence" error, there is a slight typo, should be: \setlength{\droptitle}{5em} . It's subtle enough to miss upon reading :) Also, if you want to move the title up, rather than down on the page, make this value negative, i.e. \usepackage{titling} \setlength{\droptitle}{-5em} . This solution works nicely for this usecase, thanks @Hongtao HaoDominican

© 2022 - 2024 — McMap. All rights reserved.