1
votes

I am using Rmarkdown to output pdf file. Here is the code:

---
title: |
  | This is title
  |
  | \vspace{-5truemm}Supplementary Material\vspace{-5truemm}
author: 'xxx^[Correspondence to: xxx. Email: xxx]'
geometry: margin=0.3in
fontfamily: mathpazo
fontsize: 11pt
documentclass: article
urlcolor: blue
output: 
  pdf_document:
    toc: true
    toc_depth: 4
    number_sections: yes
subparagraph: yes
header-includes: |
  \usepackage{titlesec}
  \titlespacing{\title}{0pt}{\parskip}{-\parskip}
---

\vspace{-5truemm}

# Introduction
This is introduction...

# Installation
This is installation...

## test1

### subtest1

And I want to know how to reduce space between the title (Supplementary Material) and content (not the body because I set toc as true).

Many thanks advanced!

1

1 Answers

1
votes

As described in TeXSO, you can use the following package:

\usepackage{tocloft}
\setlength{\cftbeforetoctitleskip}{-\baselineskip}

So, the complete example would be like this.

---
title: |
  | This is title
  |
  | \vspace{-5truemm}Supplementary Material\vspace{-5truemm}
author: 'xxx^[Correspondence to: xxx. Email: xxx]'
geometry: margin=0.3in
fontfamily: mathpazo
fontsize: 11pt
documentclass: article
urlcolor: blue
output: 
  pdf_document:
    toc: true
    toc_depth: 4
    number_sections: yes
subparagraph: yes
header-includes: |
  \usepackage{titlesec}
  \titlespacing{\title}{0pt}{\parskip}{-\parskip}
  \usepackage{tocloft}
  \setlength{\cftbeforetoctitleskip}{-\baselineskip}
---

<!-- 
The following \vspace{} changes the spacing 
between the first section ("Introduction" here)
and the last line of the title ("Supplementary Material")
-->
\vspace{-5truemm}

# Introduction
This is introduction...

# Installation
This is installation...

## test1

### subtest1

Note that the \vspace{} before the # Introduction changes the spacing between the first section (Introduction here) and the last line of the title (Supplementary Material). Thus, the \vspace{} has nothing to do with the space between the title and TOC.