使用 knitr 从 Rmarkdown 创建 PDF 时减少标题页边距

Reduce title margins when creating PDF from Rmarkdown using knitr

我正在使用 knitr + Rmarkdown 创建 PDF 文档。我在 yaml header 中设置了 geometry: margin=0.1in。此页边距适用于文档的 body 文本,但标题距离文档顶部很远,body 文本也是如此。这是屏幕截图:

下面是在屏幕截图中创建文档的 Rmd 代码:

---
title: "test"
output: 
  pdf_document:
    latex_engine: xelatex
geometry: margin=0.1in
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

a bunch of text to demonstrate that the margin applies only to the body text of
this document, while the title (above) remains quite far from the top of the
document, and this is messing up my plan to make a document that's only one page
in length

我需要这份文件有一页的长度。标题的巨大利润搞砸了。 如何减少标题、文档顶部和 body 文本之间的空白?

注:由于原因,我这里只能使用xelatex乳胶引擎

使用 LaTeX 代码,您可以:

  • \vspace{-1cm}

  • 减少标题和正文之间的space
  • 使用 YAML 中 title 中的相同代码减少上边距

这是你的例子:

---
title: \vspace{-1.5cm} test
output: 
  pdf_document:
  latex_engine: xelatex
geometry: margin = 0.1in
---

\vspace{-1cm}
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

a bunch of text to demonstrate that the margin applies only to the body text of
this document, while the title (above) remains quite far from the top of the
document, and this is messing up my plan to make a document that's only one page in length