使用classoption时无法从R markdown生成横向微软word文档:风景

Posted

技术标签:

【中文标题】使用classoption时无法从R markdown生成横向微软word文档:风景【英文标题】:Unable to produce landscape orientation microsoft word document from R markdown when using classoption: landscape 【发布时间】:2018-10-09 11:07:33 【问题描述】:

在使用 RStudio 和 Rmarkdown 时,我无法生成横向文档。

R 是 3.4.2 版 RStudio 是版本 0.98.1103

我无法更改这些,因为它们是我运行程序的集群上的最新版本。

编织文档后,我确实得到了一个文档(纵向形式),但是收到以下错误消息:

Output created: test_landscape.docx
Warning message:
In (function (toc = FALSE, toc_depth = 3, fig_width = 5, fig_height = 4,  :
  table of contents for word_document requires pandoc >= 1.14

可重现的代码在这里:

---
title: "test_landscape"
author: "Name"
date: "09/10/2018"
output: word_document
classoption: landscape
---

Test for landscape orientation

```r
summary(cars)
```

You can also embed plots, for example:

```r, echo=FALSE
plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

不确定这是否更适合交叉验证,因为 R 是一种统计编程语言,但问题不是统计问题。

谢谢。

编辑:在下面的评论之后编辑了标题以更好地代表我的问题。

【问题讨论】:

classoption 用于通过 LaTeX 输出 PDF。我想您必须为横向格式的 Word 输出使用不同的模板。 【参考方案1】:

感谢拉尔夫·斯图纳。

这里有一个很好的解释如何专门针对 word 执行此操作的过程:https://rmarkdown.rstudio.com/articles_docx.html

您必须创建一个具有所需设置(例如横向)的 Word 文档,将其保存在与 .Rmd 文件相同的位置,然后将其作为参考文档引用,例如:

---
title: "test_landscape"
author: "Name"
date: "09/10/2018"
output: 
  word_document:
    reference_docx: word_styles.docx
---

【讨论】:

这是一个强大的解决方案,它有很多优点,但也有很多可能的、不可预知的错误,因为 Word。我会指出,标题似乎需要 YAML 正确解释换行符和缩进,至少在我探索这个选项时是这样。

以上是关于使用classoption时无法从R markdown生成横向微软word文档:风景的主要内容,如果未能解决你的问题,请参考以下文章

ClassOptions Schema - Angular Schematics

用于 rmarkdown 的 YAML 中的内联 R 代码不运行

从 R 中的 GMT 转换时考虑夏令时

无法使用 R 中 readtext 包中的 readtext() 替换从 PDF 文件中提取的文本中的“\r\n-”

从 R 驱动声卡

使用 foreach 时无法从同一包中找到函数(Windows 开发)