3

我正在使用 Papaja 和 Rmarkdown 编写报告,并且我想在整个过程中突出显示各种文本。使用乳胶或纯 Rmarkdown 这样做很容易,但是当我使用 Papaja 的 Knitr 应用程序将报告编译为 PDF 时,我收到“未定义的控制序列”错误。

此处回答了有关在单个 Rmarkdown 文件中突出显示文本的类似问题:RMarkdown / pandoc failed to knit Pdf with latex color commands。我想知道使用 Papaja 的多个 Rmarkdown 文件是否存在答案。

我将在下面包含一个最小的示例。

1) 名为 papaja_file.Rmd 的文件

---

# https://crsh.github.io/papaja_man/index.html

title             : "Some Title"
shorttitle        : "HEADER"

author: 
  - name          : "Name R Here"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "Include addresss"
    email         : "randomemail@usa.edu"

affiliation:
  - id            : "1"
    institution   : "Any University"



author_note: |
  ....

abstract: |
  Text here for abstract. 

keywords          : "Keyword1, keyword2, keyword3"
bibliography      : ["references.bib"]

figsintext        : no
figurelist        : no
tablelist         : no
footnotelist      : no
lineno            : yes

lang              : "english"
class             : "man"
output            : papaja::apa6_pdf
---

```{r load_packages, include = FALSE}
library("papaja")
```

```{r analysis_preferences}
# Seed for random number generation
set.seed(42)
```

```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.path = 'figures/', echo = TRUE, warning = FALSE, message = FALSE)
```


```{r child = 'child_document.Rmd'}
```


\newpage

# References
```{r create_references, echo = F}
r_refs(file = "references.bib")
```

\setlength{\parindent}{-0.5in}
\setlength{\leftskip}{0.5in}

请注意,它引用了单个子 Rmarkdown 文档。

2)带有文本的子文档,称为child_document.Rmd

---
output: 
  pdf_document:
      includes:
          in_header: preamble.tex
---

One sentence without highlighting. \hl{Another with highlighting.}

3) 序言,称为 preamble.tex

\usepackage{color}
\usepackage{soul}
\definecolor{lightblue}{rgb}{0.90, 0.95, 1}
\sethlcolor{lightblue}

编织主 papaja 文件会产生错误。删除子文档中的 \hl 命令可以使 pdf 顺利编译。

将 YAML 标头放入主 papaja 文档而不是子文档后的结果:

在此处输入图像描述

4

1 回答 1

2

未评估子文档中的 YAML 标头,参见

例如,主文档由 YAML 前端内容和子文档组成,这些子文档本身就是没有 YAML 前端内容的 R Markdown 文档。

https://crsh.github.io/papaja_man/tips-and-tricks.html#splitting-an-r-markdown-document

但是您可以使用以下方法将您的主文件包含preamble.tex在您的主文件中:

output: 
  papaja::apa6_pdf:
    includes:
      in_header: preamble.tex

cf https://github.com/rstub/stackoverflow/commit/a92a67d4721ee9c06e995b08adbf8cb89daebcb4

结果:

在此处输入图像描述

于 2019-07-16T18:15:03.467 回答