【问题标题】:Reduce title margins when creating PDF from Rmarkdown using knitr使用 knitr 从 Rmarkdown 创建 PDF 时减少标题边距
【发布时间】:2020-05-07 15:51:31
【问题描述】:

我正在使用 knitr + Rmarkdown 创建 PDF 文档。我在 yaml 标头中设置了geometry: margin=0.1in。此页边距适用于文档的正文,但标题与正文以及正文的顶部相距甚远。截图如下:

这是在屏幕截图中创建文档的 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

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

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

【问题讨论】:

    标签: r latex r-markdown knitr


    【解决方案1】:

    使用 LaTeX 代码,您可以:

    • \vspace{-1cm}缩小标题和文本之间的间距

    • 使用 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
    

    【讨论】:

    • 请注意,如果您的标题被引用,则 vspace 调用需要在引号内并带有额外的转义斜杠,例如"\\vspace{-1.5cm} test"
    • 感谢@DHW 提供这个重要提示。我只是可以补充一点,它仅适用于我在第一次尝试时监督的大括号(来自 R)。
    • @AgileBean 与什么相反?它是否适用于具有不同字符的其他上下文?我不知道。
    • 我只是视力不好,输入了 \vspace(-1in)。没看到它们是大括号
    • 我想要的是一个不修改标题的解决方案,这样编织成HTML时就没有问题
    猜你喜欢
    • 2020-12-01
    • 1970-01-01
    • 2015-12-05
    • 2015-12-02
    • 2016-01-11
    • 1970-01-01
    • 2012-12-13
    • 2021-02-06
    • 1970-01-01
    相关资源
    最近更新 更多