Jordan Campos
Jordan Campos

Reputation: 31

R Markdown Heading/Body spacing format

I'm sure this is already out there but I can't seem to find it. How can I change the spacing between a header and body text in an RMarkdown file for a PDF output? I'm not very well versed in TeX or pandoc, so I am wondering if there is a simple way to do this in the YAML header?

Thanks!

Edit:

Here is the code I have when that I have (I thought this was called the YAML header in the RMarkdown file but I am somewhat knew to markdown formatting so that could be wrong).

---
title: "Predicting Diabetes"
author: "Jordan"
date: "April 28, 2018"
output: 
   pdf_document:
    pandoc_args: [
      "-V", "classoption=twocolumn"
    ]
---

Currently I have created a two-column format of my PDF, but the headers seem to be somewhat spread out, so I am wondering if there is anything to add to the above that can adjusted the spacing between the header and body text. I am inserting a picture of what I mean by the spacing between headers being fairly large.

Upvotes: 3

Views: 4843

Answers (1)

hpesoj626
hpesoj626

Reputation: 3629

One way to do this is to use header-includes in order to use the LaTeX titlesec package for adjusting the spaces before and after the headers.

Here is the YAML code.

---
title: "Predicting Diabetes"
author: "Jordan"
date: "April 28, 2018"
output: 
   pdf_document:
    pandoc_args: [
      "-V", "classoption=twocolumn"
    ]
subparagraph: yes
header-includes: |
  \usepackage{titlesec}
  \titlespacing{\section}{0pt}{12pt plus 2pt minus 1pt}{0pt plus 1pt minus 1pt}
  \titlespacing{\subsection}{0pt}{12pt plus 2pt minus 1pt}{0pt plus 1pt minus 1pt}
  \titlespacing{\subsubsection}{0pt}{12pt plus 2pt minus 1pt}{0pt plus 1pt minus 1pt}
---

Here are the important aspects of this approach:

  1. subparagraph: yes. You need this in order to use titlesec. \subparagraph is redefined in the pandoc template for LaTeX by default (the else$ part in pandoc).

  2. Here is a post that explains really well how \titlespacing works.

Upvotes: 6

Related Questions