如何减少Rmarkdown的pdf_output中标题和内容之间的空间

时间:2020-09-19 09:57:16

标签: r-markdown

我正在使用Rmarkdown输出pdf文件。这是代码:

---
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

我想知道如何减少标题(补充材料)和内容(不是正文,因为我将toc设置为true)之间的空间。

非常感谢!

1 个答案:

答案 0 :(得分:1)

TeXSO中所述,您可以使用以下软件包:

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

因此,完整的示例将是这样。

---
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

请注意,\vspace{}之前的# Introduction会改变间距 在第一部分(此处是简介)之间 标题的最后一行(补充材料)。 因此,\vspace{}与 标题和目录之间的空格。