使用Knitr从Rmarkdown创建PDF时减少标题边距 [英] Reduce title margins when creating PDF from Rmarkdown using knitr

查看:230
本文介绍了使用Knitr从Rmarkdown创建PDF时减少标题边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用knitr + Rmarkdown创建PDF文档.我在yaml标头中设置了geometry: margin=0.1in.此页边距适用于文档的正文,但是标题和正文距文档的顶部相距甚远.这是屏幕截图:

I'm creating a PDF document using knitr + Rmarkdown. I've set geometry: margin=0.1in in the yaml header. This margin applies to the body text of the document, but the title is quite far from the top of the document, as well as the body text. Here's a screenshot:

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

Here's the Rmd code that created the document in the screenshot:

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

我需要此文档的长度为一页.标题的巨额利润使这一点搞砸了. 如何缩小标题,文档顶部和正文之间的空格?

I need this document to be one page in length. The title's huge margins are messing that up. How can I reduce the whitespace between the title, the top of the document, and the body text?

注意:出于某些原因,我只能在这里使用xelatex乳胶引擎.

推荐答案

使用LaTeX代码,您可以:

Using LaTeX code, you can:

  • 使用\vspace{-1cm}

使用与YAML中的title相同的代码减少上边距

reduce the top margin with the same code placed in title in the YAML

这是您的示例:

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

这篇关于使用Knitr从Rmarkdown创建PDF时减少标题边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆