在 knitr 选项中将行间距调整为 1.5 间距

Adapt linespacing to 1.5-spacing in knitr options

我想将以下代码调整为 1.5 行距,而不是常规输出的双倍行距:

```{r setup, include=FALSE}
hook_chunk = knitr::knit_hooks$get('chunk')

knitr::knit_hooks$set(chunk = function(x, options) {
  regular_output = hook_chunk(x, options)
  # add latex commands if chunk option singlespacing is TRUE
  if (isTRUE(options$singlespacing)) 
    sprintf("\singlespacing\n %s \n\doublespacing", regular_output)
  else
    regular_output
})

knitr::opts_chunk$set(echo = TRUE, singlespacing = TRUE)
```

代码原为postet

我怎样才能做到这一点? 感谢您的帮助!

尝试在 YAML header 中定义 LaTeX 包 setspace 并直接将 \onehalfspacing 设置为 LaTeX 命令。

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

\onehalfspacing

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.