R markdown format title - pdf output

10,115

Solution 1

I'm not sure exactly how you want the document to look, but here are some ways to control spacing and fontsize with Latex tags. In the rmd document below:

  1. The initial \vspace{5cm} adds space above the first line of the title. \vspace{0.5cm} adds space between the two lines of the title.
  2. \LARGE and \Large give different font sizes on different lines of the title.
  3. | at the beginning of each line of the title allows a multi-line title.
  4. If you want a separate cover page, \newpage at the beginning of the main document will start the main document text on a new page after the title page.

---
title: | 
  | \vspace{5cm} \LARGE My Title is really long and takes up several lines of text
  | \vspace{0.5cm} \Large My Title is really long and takes up several lines of text
author: "eipi10"
date: "5/16/2017"
output: pdf_document
---

\newpage

Document text here.

Solution 2

For a smaller title section, the following may be helpful. It builds on eipi10's answer but with two modifications:

  1. the vspace{} commands include negative values to shrink white space
  2. the fontsize code uses the more cumbersome begin{} and end{} syntax because, with simpler code like \normalsize{}, I found extraneous braces appeared around the title, name, etc.

---
title: \vspace{-0.75cm} \begin{normalsize} My Title \end{normalsize} \vspace{-0.5cm}
author: \begin{normalsize} My Name \end{normalsize}
date: \begin{normalsize} 5/16/2017 \end{normalsize}
output: pdf_document
---
Share:
10,115
Jordan
Author by

Jordan

Grad student in fisheries.

Updated on June 07, 2022

Comments

  • Jordan
    Jordan almost 2 years

    I'm sure this is already out there but I can't seem to find it. How can I change the font size and spacing for the title in an R markdown document compiled as a pdf?

    Thanks!

  • gaelgarcia
    gaelgarcia about 6 years
    Is there a way to do exactly this but for HTML output?
  • samcarter_is_at_topanswers.xyz
    samcarter_is_at_topanswers.xyz almost 3 years
    \LARGE is a switch and does not take an argument, so it should be {\LARGE ...}. Without starting a new paragraph after it, the spacing to the following line will be wrong.
  • samcarter_is_at_topanswers.xyz
    samcarter_is_at_topanswers.xyz almost 3 years
    \normalsize{...} is incorrect syntax. Such font commands are switches and don't take an argument, so it would have to be {\normalsize ...}. However as you correctly observed, this will result in incorrect spacing if no new paragraph is started afterwards.
  • eipi10
    eipi10 almost 3 years
    Thanks, I've updated my answer, but without the braces (which show up in the rendered version).