multiple authors and subtitles in Rmarkdown yaml

纵然是瞬间 提交于 2019-12-03 02:12:53

问题


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?


回答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.




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



回答3:


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



回答4:


I've also had this problem. Following the suggestion from @tmpname12345 I modified the latex template (default.tex) and the html template (default.html) to render subtitles. This pull request is on github rstudio/rmarkdown if you want the code quickly, and looks like it will be standard in rmarkdown next time they push to CRAN.




回答5:


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

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




回答6:


Add to the answer by Ze Grisi, i just discovered adding html heading tags into the yaml works to adjust the font in the title and subtitle. Note the quotation marks are no longer needed.

---
title:  'This is the title: it contains a colon'
subtitle: <h1>This is the subtitle</h1>
output: pdf_document
---

For a more dramatic effect add an underline to the subtitle

---
title:  'This is the title: it contains a colon'
subtitle: <h1><u>This is the subtitle</u></h1>
output: pdf_document
---


来源:https://stackoverflow.com/questions/26043807/multiple-authors-and-subtitles-in-rmarkdown-yaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!