Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple authors and subtitles in Rmarkdown yaml

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?

like image 934
Eric Green Avatar asked Sep 25 '14 16:09

Eric Green


4 Answers

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
---
like image 156
Ze Grisi Avatar answered Nov 15 '22 03:11

Ze Grisi


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.

like image 30
tmpname12345 Avatar answered Nov 15 '22 01:11

tmpname12345


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

like image 20
Michael Harper Avatar answered Nov 15 '22 03:11

Michael Harper


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
---
like image 13
Corrado Avatar answered Nov 15 '22 03:11

Corrado