【问题标题】:Rmarkdown and Latex format citations with round paranthesis带有圆括号的 R Markdown 和 Latex 格式引用
【发布时间】:2020-03-23 17:57:07
【问题描述】:

我觉得这是一件直截了当的事情,但我发现的一切并不能完全满足我的需求。我正在使用 并编织到 .pdf。我想让我的文本引用有round () 括号而不是块括号。下面的 使用references.bib 文件来正确导入引用。有什么办法可以轻松地将括号更改为圆吗?

---
title: "Title"
author: "Author"
date: "16/03/2020"
output: 
  pdf_document:
    fig_caption: yes
    citation_package: natbib
  bibliography: references.bib  
editor_options: 
  chunk_output_type: console
---

我使用了here的方法,但是它返回一个错误:

Error in yaml::yaml.load(..., eval.expr = TRUE) : 
  Parser error: while parsing a block mapping at line 6, column 5 did not 
  find expected key at line 7, column 30`

    ---
    title: "Title"
    author: "Author"
    date: "16/03/2020"
    output: 
      pdf_document:
        fig_caption: yes
      bibliography: references.bib  
    editor_options: 
      chunk_output_type: console
    \usepackage[round]{natbib}
    ---

有什么想法吗?感谢您的建议/想法...

【问题讨论】:

  • 您不能在 rmarkdown 标头中使用方括号。一种解决方法是将命令“隐藏”在头文件中。参见例如stackoverflow.com/a/58673002
  • 对不起,我没有关注你的其他答案。
  • 如果你将\usepackage[round]{natbib}保存在一个名为preamble.tex的文件中,你可以将includes: in_header: preamble.tex添加到你的markdown文档中
  • 如果您可以创建一个 minimal reproducible example 来实际引用某些内容并包含运行它所需的围兜条目,我可以尝试制作一些工作代码示例

标签: rmarkdown latex yaml r latex r-markdown citations


【解决方案1】:

您尝试在 rmarkdown 标头中包含 \usepackage[round]{natbib} 的问题是 rmarkdown 似乎不够聪明,无法解析带有可选参数的命令。可以通过将命令隐藏在 .tex 文件中来欺骗它

---
title: "Title"
author: "Author"
date: "16/03/2020"
output: 
  pdf_document:
    fig_caption: yes
    includes:
      in_header: preamble.tex
bibliography: references.bib  
---

test [@knuth]

preamble.tex

\usepackage[round]{natbib}

https://rstudio.cloud/project/1061588

【讨论】:

    【解决方案2】:

    使用header-includes: 选项应该可以解决问题。

    ---
    title: "Title"
    author: "Author"
    date: "16/03/2020"
    output: 
      pdf_document:
        fig_caption: yes
        citation_package: natbib
      bibliography: references.bib  
    editor_options: 
      chunk_output_type: console
    header-includes:
        - \usepackage[round]{natbib}
    ---
    

    【讨论】:

      猜你喜欢
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多