multiple authors and subtitles in Rmarkdown yaml

86,967

Solution 1

The default latex template in rmarkdown does not support author affiliations or subtitles. It does support multiple authors however, the correct yaml syntax is

---
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
---

If you want to customize your header, the best approach is to modify the latex template, found here to suit your needs. Then copy it to your local directory and pass it to the header in the template field.

Solution 2

I just found out that it is possible to add subtitles to R markdown PDF output. I am using R 3.2.2 and RStudio 0.99.473 in Ubuntu 14.04.

---
title:  'This is the title: it contains a colon'
subtitle: 'This is the subtitle'
output: pdf_document
---

Solution 3

As explained in the main answer, the default R Markdown template does not support author affiliations. While users can edit the template file to add their own custom YAML fields, there are easier some workarounds you can use for PDF or HTML outputs.

HTML Outputs

You can use the recently released radix template. First you must install the package:

install.packages("radix")

Once installed, you must set the

---
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

enter image description here

PDF Outputs

You can use premade templates, and there are some good examples within the rticles package. First we must install the package:

install.packages("rticles")

Once Installed, you can use one of the templates, such as the Journal of Statistical Software:

---
author:
  - name: FirstName LastName
    affiliation: University/Company
    address: >
      First line
      Second line
    email: \email{[email protected]}
    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
---

enter image description here

Solution 4

If you render a pdf, LaTex use authors' footnote for affiliations (i.e. converting numbering in symbles). Try

---
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
---

Solution 5

I've found a solution to your subtitle part of the question here: https://stackoverflow.com/a/41444545/14027216

You can add subtitle by adding subtitle: to your code and multiple subtitles can be added as follow:

---
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
---

You can add more than two subtitles, but I don't know the maximum amount. Each subtitle will be displayed in new line.

Share:
86,967
Eric Green
Author by

Eric Green

Updated on July 31, 2020

Comments

  • Eric Green
    Eric Green almost 4 years

    I'm trying to follow this pandoc example to add multiple authors to an Rmarkdown file in the yaml metadata block. The pdf will generate in RStudio (Version 0.98.932), but there is no author information.

    ---
    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
    ---
    

    I'd also like to customize the heading a bit more and add a subtitle. Possible?

  • Brandon Bertelsen
    Brandon Bertelsen about 9 years
    Doesn't seem to support abstract, as mentioned here.
  • jciloa
    jciloa over 6 years
    This answer is not correct in that yaml does support subtitles! See below (stackoverflow.com/a/33680803/5124002).
  • Corrado
    Corrado almost 5 years
    This answer is not correct in that yaml does support subtitles, and you can add standard LaTeX syntax for the affiliations if your output is in PDF. See below: stackoverflow.com/a/37777804/4434088
  • Frans Rodenburg
    Frans Rodenburg over 4 years
    To those wondering how to add authors with the same affiliations: tex.stackexchange.com/a/61304/144923
  • zenTheo
    zenTheo about 4 years
    It is tested only in pdf output!