r - 在pdf输出中编织时如何在R Markdown中证明(两边)文本
解决方案
R Markdown 应该默认使用两端对齐的文本。但是,如果您只想导出为 PDF,我们可以直接在文档中使用 LaTeX 命令。使用标准参数\centering
\raggedright
和\raggedleft
,如此处所述。
这是一个最小的例子:
---
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 中加载它:
---
output: pdf_document
header-includes:
- \usepackage[document]{ragged2e}
---
\raggedleft
**Ragged Left**
`r lipsum[1]`
\justify
**Revert to Justified**
`r lipsum[1]`
编辑
如果您使用的是papaja
模板,则需要包含所有 YAML。不提供作者、短标题或其他字段将导致它崩溃。
---
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]`
推荐阅读
- java - 属性名称以“set”开头时未映射的目标属性警告
- firebase - Firebase 存储为 PNG 文件提供 StorageTaskEventType.failure(尝试上传 iOS 屏幕截图)
- php - 通过 ssh 将远程 mysql 服务器连接到 symfony(doctrine)
- spring-boot - 无法使用 eureka 客户端运行服务。它因“无法创建泽西客户端”错误而中断
- css - 具有边框半径的 div 上的 box-shadow 稍微偏离中心
- android - 在片段内单击按钮后没有出现吐司?
- mysql - Mysql 在一张表上加入日期
- mongodb - 为什么 MongoDB bulkWrite 不支持 insertMany?
- c# - 生成的对象值(声音/分数)在 Android 上混合,但在 Unity2D 中是正确的
- matlab - Matlab:滑动存储在单元格数组中的图像