【问题标题】:multiple authors and subtitles in Rmarkdown yamlRmarkdown yaml中的多个作者和字幕
【发布时间】:2014-11-20 12:50:24
【问题描述】:

我正在尝试关注this pandoc example 将多个作者添加到yaml metadata block 中的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
---

我还想进一步自定义标题并添加副标题。可能吗?

【问题讨论】:

  • 尝试删除破折号 -。并确保您使用 \t 对我来说它是这样工作的
  • 你把\t放在哪里?
  • 哦,对不起,我删除了第二作者进行测试忘记了。不能两次调用作者密钥。因此,您可以执行类似“Name1 & Name2”的操作。我相信,从属关系也是最新 yaml 的未知参数。

标签: r yaml rstudio r-markdown


【解决方案1】:

我刚刚发现可以在 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
---

【讨论】:

    【解决方案2】:

    rmarkdown 中默认的 Latex 模板不支持作者单位或字幕。它确实支持多个作者,但是正确的 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
    ---
    

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

    【讨论】:

    【解决方案3】:

    如主要答案中所述,默认的 R Markdown 模板不支持作者从属关系。虽然用户可以编辑模板文件以添加他们自己的自定义 YAML 字段,但您可以使用一些更简单的解决方法来输出 PDF 或 HTML。

    HTML 输出

    您可以使用最近发布的radix template。首先你必须安装包:

    install.packages("radix")
    

    一旦安装,您必须设置

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

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

    install.packages("rticles")
    

    安装后,您可以使用其中一种模板,例如 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
    ---
    

    【讨论】:

      【解决方案4】:

      如果您呈现 pdf,LaTex 使用作者的脚注作为附属关系(即转换符号中的编号)。试试

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

      【讨论】:

      【解决方案5】:

      我在这里找到了问题的字幕部分的解决方案: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
      ---
      

      您可以添加两个以上的字幕,但我不知道最大数量。每个字幕都会换行显示。

      【讨论】:

        【解决方案6】:

        我也遇到过这个问题。根据@tmpname12345 的建议,我修改了latex 模板(default.tex)和html 模板(default.html)来渲染字幕。如果您想要快速获取代码,此拉取请求位于 github rstudio/rmarkdown,并且看起来它将在下次推送到 CRAN 时成为 rmarkdown 中的标准。

        【讨论】:

          【解决方案7】:

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

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

          要获得更戏剧化的效果,请在副标题中添加下划线

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

          【讨论】:

            【解决方案8】:

            @greg 在enter link description here 使用乳胶解决方案。我将乳胶代码放入 rmarkdown yaml 标头 进行了一些更改,它完成了这项工作。

            ---
            title: 'Some Title'
            author: Author One$^1$ \and 
                    Author Two$^2$ \and
                    Author Three$^3$ 
            date: $^1$Organization 1 \newline
                  $^2$Organization 2 \newline
                  $^3$Organization 3 
                \newline  
                \newline
                \today 
            output: 
            ---
            

            诀窍是将隶属关系放入 date 标记中。

            【讨论】:

            • 只在pdf输出中测试!
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2020-02-14
            • 2021-06-24
            • 1970-01-01
            • 1970-01-01
            • 2014-10-12
            • 1970-01-01
            相关资源
            最近更新 更多