【问题标题】:How to properly set rendering Rmarkdown to pdf?如何正确地将渲染 Rmarkdown 设置为 pdf?
【发布时间】:2021-07-27 12:25:02
【问题描述】:

我使用 Rmarkdown 生成报告,如果我的行太长,渲染后通常会被剪掉。

有办法解决吗?

我附上屏幕截图以便更好地解释我的问题。

【问题讨论】:

标签: r pdf r-markdown


【解决方案1】:

您可以使用块选项tidy=TRUE 在代码中自动插入换行符。

---
output: pdf_document
---

```{r, tidy = TRUE}
c(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
```

换行符由formatR::tidy_source() 插入。详情请见https://yihui.org/knitr/options/#code-decoration

chunk_content <- "c(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)"
formatR::tidy_source(text = chunk_content, width.cutoff = 30)
#> c(1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
#>     1, 2, 3, 4, 5, 6, 7, 8, 9,
#>     0, 1, 2, 3, 4, 5, 6, 7, 8,
#>     9, 0, 1, 2, 3, 4, 5, 6, 7,
#>     8, 9, 0)

【讨论】:

  • Option tidy=TRUE 没有帮助我不确定它是否也是与操作系统相关的东西。我在安装了 MikiTex 的 Windows 上使用 Rstudio 来读取 PDF。
  • 所以我想自从答案被接受后,该解决方案最终奏效了?您能否解释一下为什么这最初不起作用?
猜你喜欢
  • 1970-01-01
  • 2018-12-25
  • 2020-11-12
  • 2022-07-27
  • 2016-04-17
  • 1970-01-01
  • 2017-05-26
  • 2018-11-30
  • 1970-01-01
相关资源
最近更新 更多