1

我正在尝试制作自己的 APA7 风格的 Rmarkdown 模板(带有 pdf 输出)。目前感觉还不错。我唯一需要解决的是代码块中的双倍间距。

我很快找到了这个线程,它解决了如何使用以下代码加倍空间的问题。

header-includes:
    - \usepackage{setspace}\doublespacing

但是,双倍间距也适用于我希望它们是单个空格的代码块。\singlespacing我知道我可以在块之前和之后添加类似的东西,但是由于我使用了很多夹头,有没有更聪明的方法?

有没有办法避免\doublespacing代码块中产生的双倍间距?


编辑

这是一个可重现的例子。

---
output: pdf_document
header-includes:
  - \usepackage{setspace}\doublespacing
---

I am trying to make my own APA7 style Rmarkdown template (with pdf output). Feel pretty good so far. The only thing left for me to fix is the double spacing in code chunks.

```{r}
# This chuck is also double spaced
# But I would prefer it to be single spaces
```

在此处输入图像描述

4

1 回答 1

1

Rmarkdown 定义了一个Shaded环境,用来设置这些代码片段。您可以对其进行修补以自动添加\singlespace

---
output: 
  pdf_document:
    keep_tex: true
header-includes:
  - \usepackage{setspace}\doublespacing
  - \usepackage{etoolbox}
  - \AtBeginEnvironment{Shaded}{\singlespace}
---

I am trying to make my own APA7 style Rmarkdown template (with pdf output). Feel pretty good so far. The only thing left for me to fix is the double spacing in code chunks.

```{r}
# This chuck is also double spaced
# But I would prefer it to be single spaces
```
I am trying to make my own APA7 style Rmarkdown template (with pdf output). Feel pretty good so far. The only thing left for me to fix is the double spacing in code chunks.

在此处输入图像描述

于 2022-02-07T20:21:30.787 回答