Rmarkdown yaml中的多个作者和副标题

Eri*_*een 43 yaml r rstudio r-markdown

我正在尝试按照此pandoc示例将多个作者添加到yaml元数据块中的Rmarkdown文件.pdf将在RStudio(版本0.98.932)中生成,但没有作者信息.

---
title:  'This is the title: it contains a colon'
author:
- name: Author One
  affiliation: University of Somewhere
- name: Author Two
  affiliation: University of Nowhere
date: "`r format(Sys.time(), '%d %B %Y')`"
tags: [nothing, nothingness]
abstract: |
  This is the abstract.

  It consists of two paragraphs.
output: pdf_document
---
Run Code Online (Sandbox Code Playgroud)

我还想更多地定制标题并添加一个副标题.可能?

小智 44

我刚刚发现可以在R markdown PDF输出中添加字幕.我在Ubuntu 14.04中使用R 3.2.2和RStudio 0.99.473.

---
title:  'This is the title: it contains a colon'
subtitle: 'This is the subtitle'
output: pdf_document
---
Run Code Online (Sandbox Code Playgroud)


tmp*_*345 36

rmarkdown中的默认乳胶模板不支持作者从属关系或字幕.它确实支持多个作者,但正确的yaml语法是

---
title:  'This is the title: it contains a colon'
author:
- Author One
- Author Two
date: "`r format(Sys.time(), '%d %B %Y')`"
tags: [nothing, nothingness]
abstract: |
  This is the abstract.

  It consists of two paragraphs.
output: 
    pdf_document:
        template: NULL
---
Run Code Online (Sandbox Code Playgroud)

如果您想自定义标题,最好的方法是修改乳胶模板,在此处找到以满足您的需求.然后将其复制到本地目录并将其传递到template字段中的标题.

  • 这个答案是不正确的,因为Yaml确实支持字幕!参见下文(/sf/answers/2357656241/)。 (4认同)

Cor*_*ado 10

如果你渲染一个pdf,LaTex使用作者的脚注来表示隶属关系(即转换symbles中的编号).尝试

---
title:  'This is the title: it contains a colon'
subtitle: 'This is the subtitle'
author:
- Author One^[University of Somewhere]
- Author Two^[University of Nowhere]
date: "`r format(Sys.time(), '%d %B %Y')`"
tags: [nothing, nothingness]
abstract: |
  This is the abstract.

  It consists of two paragraphs.
output: pdf_document
---
Run Code Online (Sandbox Code Playgroud)


Joh*_*nSG 7

我也遇到过这个问题.根据@ tmpname12345的建议,我修改了乳胶模板(default.tex)和html模板(default.html)来渲染字幕.如果你想快速获得代码,这个拉取请求就在github rstudio/rmarkdown上,看起来它们在下次推送到CRAN时将成为rmarkdown的标准.


Mic*_*per 7

如主要答案中所述,默认的R Markdown模板不支持作者隶属关系。尽管用户可以编辑模板文件以添加自己的自定义YAML字段,但可以将一些变通方法用于PDF或HTML输出。

HTML输出

您可以使用最近发布的基数模板。首先,您必须安装该软件包:

install.packages("radix")
Run Code Online (Sandbox Code Playgroud)

安装完成后,您必须设置

---
title: "Radix for R Markdown"
description: | 
  Scientific and technical writing, native to the web
date: May 4, 2018
author:
  - name: "JJ Allaire"
    url: https://github.com/jjallaire
    affiliation: RStudio
    affiliation_url: https://www.rstudio.com
  - name: "Rich Iannone"
    url: https://github.com/rich-iannone
    affiliation: RStudio
    affiliation_url: https://www.rstudio.com
output: radix::radix_article
---

Your content
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

PDF输出

您可以使用预制模板,并且在rticles包中有一些很好的示例。首先,我们必须安装该软件包:

install.packages("rticles")
Run Code Online (Sandbox Code Playgroud)

安装后,您可以使用其中一个模板,例如Journal of Statistics Software:

---
author:
  - name: FirstName LastName
    affiliation: University/Company
    address: >
      First line
      Second line
    email: \email{name@company.com}
    url: http://rstudio.com
  - name: Second Author
    affiliation: Affiliation
title:
  formatted: "A Capitalized Title: Something about a Package \\pkg{foo}"
  # If you use tex in the formatted title, also supply version without
  plain:     "A Capitalized Title: Something about a Package foo"
  # For running headers, if needed
  short:     "\\pkg{foo}: A Capitalized Title"
abstract: >
  The abstract of the article.
keywords:
  # at least one keyword must be supplied
  formatted: [keywords, not capitalized, "\\proglang{Java}"]
  plain:     [keywords, not capitalized, Java]
preamble: >
  \usepackage{amsmath}
output: rticles::jss_article
---
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


小智 7

我在这里找到了问题的副标题部分的解决方案:https : //stackoverflow.com/a/41444545/14027216

您可以通过添加subtitle:到代码中来添加字幕,并且可以添加多个字幕,如下所示:

---
title:  'This is the title: it contains a colon'
subtitle: |
  | 'subtitle 1'
  | 'subtitle 2'
author:
- name: Author One
  affiliation: University of Somewhere
- name: Author Two
  affiliation: University of Nowhere
date: "`r format(Sys.time(), '%d %B %Y')`"
tags: [nothing, nothingness]
abstract: |
  This is the abstract.

  It consists of two paragraphs.
output: pdf_document
---
Run Code Online (Sandbox Code Playgroud)

您可以添加两个以上的字幕,但我不知道最大数量。每个副标题将显示在新行中。


pdb*_*ley 6

在Ze Grisi的回答中,我刚刚发现在yaml作品中添加了html标题标签,以调整标题和副标题中的字体。请注意,不再需要引号。

---
title:  'This is the title: it contains a colon'
subtitle: <h1>This is the subtitle</h1>
output: pdf_document
---
Run Code Online (Sandbox Code Playgroud)

为了获得更生动的效果,请在字幕上添加下划线

---
title:  'This is the title: it contains a colon'
subtitle: <h1><u>This is the subtitle</u></h1>
output: pdf_document
---
Run Code Online (Sandbox Code Playgroud)