在pdf输出中进行编织时,如何在R Markdown中对文本进行正反对齐 [英] How to justify (to both sides) text in R Markdown when knitting in pdf output

查看:122
本文介绍了在pdf输出中进行编织时,如何在R Markdown中对文本进行正反对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找控制文本对齐方式的方法,但是我找不到PDF输出的任何内容.

I have looked for ways to control the alignment of the text, however I could not find anything for PDF outputs.

有一个现有的答案,但仅与HTML输出有关:

There is an existing answer, but related to HTML output only: How to justify the text to both sides when knitting html in rmarkdown.

推荐答案

R Markdown应该默认使用对齐文本.但是,如果您只想导出为PDF,我们可以使用标准参数\centering \raggedright\raggedleft在文档中直接使用LaTeX命令,如

R Markdown should default to using justified text. However, if you only want to export to PDF, we can directly use LaTeX commands within the document.using the standard arguments \centering \raggedright and \raggedleft, as explained here.

这是一个最小的示例:

---
output: pdf_document
---

```{r, include = FALSE}
devtools::install_github("coolbutuseless/lipsum")
library(lipsum)
```

**Default**

`r lipsum[1]`

\centering

**Centered Text**

`r lipsum[1]`

\raggedright

**Ragged Right**

`r lipsum[1]`

\raggedleft

**Ragged Left**

`r lipsum[1]`

如果要还原为对齐文本,可以使用ragged2e LaTeX软件包.您需要通过添加以下内容将其加载到YAML中:

If you want to revert to justified text, you can use the ragged2e LaTeX package. You will need to load this within the YAML by adding:

---
output: pdf_document
header-includes:
  - \usepackage[document]{ragged2e}
---

\raggedleft

**Ragged Left**

`r lipsum[1]`



\justify

**Revert to Justified**

`r lipsum[1]`

编辑

如果使用的是papaja模板,则需要包括所有YAML.不提供作者,短标题或其他字段会导致其崩溃.

Edit

If you are using the papaja template you need to include all the YAML. Not providing an author, shorttitle or another other field will cause it to crash.

---
title             : "The title"
shorttitle        : "Title"

author: 
  - name          : "First Author"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "Postal address"
    email         : "my@email.com"
  - name          : "Ernst-August Doelle"
    affiliation   : "1,2"

affiliation:
  - id            : "1"
    institution   : "Wilhelm-Wundt-University"
  - id            : "2"
    institution   : "Konstanz Business School"

author_note: |
  Add complete departmental affiliations for each author here. Each new line herein must be indented, like this line.

  Enter author note here.

abstract: |
  Enter abstract here. Each new line herein must be indented, like this line.

keywords          : "keywords"
wordcount         : "X"

bibliography      : ["r-references.bib"]

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

class             : "man"
output            : papaja::apa6_pdf
header-includes:
  - \usepackage[document]{ragged2e}
---

```{r load_packages, include = FALSE}

library(lipsum)
```
\justify

**Default**

`r lipsum[1]`

这篇关于在pdf输出中进行编织时,如何在R Markdown中对文本进行正反对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆