问题描述
在 R Markdown 中,我想要一个带有 R Markdown 原生引用样式 [@ref]
的链接引用的图形标题.但是,当我将末尾的 [@hawking_thermodynamics_1983]
片段插入标题时,它只会抛出一个错误:
!缺少插入的 $.<插入文本>$l.94 ...iontextfoo [@hawking_thermodynamics_1983]}pandoc.exe:生成 PDF 时出错错误:pandoc 文档转换失败,错误 43
示例:
这是我的代码:
---标题:《无题》作者:作者"输出:pdf_document# 参考书目:bibliography.bib参考:- 编号:hawking_thermodynamics_1983作者:- 家庭:霍金给定:S.W.- 家庭:页面给出:唐.N.出版商:数学物理通讯标题:反德西特空间中黑洞的热力学.数量:87类型:文章期刊发布:年份:1983---```{r 设置,包括=FALSE}knitr::opts_chunk$set(echo = TRUE)```## R 降价egin{图}[h]定心includegraphics[宽度=13cm]{example.jpg}caption{Captiontextfoo}label{fig1}结束{图}[@hawking_thermodynamics_1983]# 参考书目
这个输出:
我希望括号中的引文出现在图形标题内,并带有指向参考书目的工作链接.参考书目应该像往常一样自动出现.
我怎么可能做到这一点?
注意事项:
- 我也尝试了
[@...
或不带括号,但没有奏效. - 我也试过这个
caption{Captiontextfoo cite{[@hawking_thermodynamics_1983]}}
来自如果这不起作用(不完全确定为什么不起作用,但有些人似乎对上述问题有疑问),您可以使用文本引用(参见 bookdown书第2.2.4节).
(ref:caption) 绘图 [@R-rmarkdown]```{r echo=FALSE, fig.cap="(ref:caption)"}情节(汽车)```
In R Markdown, I want a figure caption with a linked citation in R Markdown native citation style
[@ref]
. However, when I insert the[@hawking_thermodynamics_1983]
snippet at the end into the caption, it's throwing just an error:! Missing $ inserted. <inserted text> $ l.94 ...iontextfoo [@hawking_thermodynamics_1983]} pandoc.exe: Error producing PDF Error: pandoc document conversion failed with error 43
Example:
This is my code:
--- title: "Untitled" author: "Author" output: pdf_document # bibliography: bibliography.bib references: - id: hawking_thermodynamics_1983 author: - family: Hawking given: S. W. - family: Page given: Don. N. publisher: Communications in Mathematical Physics title: Thermodynamics of Black Holes in Anti-de Sitter Space. volume: 87 type: article-journal issued: year: 1983 --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ## R Markdown egin{figure}[h] centering includegraphics[width=13cm]{example.jpg} caption{Captiontextfoo}label{fig1} end{figure} [@hawking_thermodynamics_1983] # Bibliography
with this output:
I want the citation in parentheses to appear inside the figure caption, with working link to the bibliography. The bibliography should appear automatically as usual.
How could I possibly achieve this?
Notes:
- I also tried
[@...
or w/o brackets but didn't work. - I tried also this
caption{Captiontextfoo cite{[@hawking_thermodynamics_1983]}}
from this answer, but didn't work as well, shows only[?]
. - R version 3.4.3 (2017-11-30)
- Platform: x86_64-w64-mingw32/x64 (64-bit)
- Running under: Windows 7 x64 (build 7601) Service Pack 1
解决方案This problem appears to be fixed, and the citation can be included directly within the
fig.cap
argument:Here is a minimal example which creates an
bib.bib
file in the same directory as the.Rmd
file. It also includes the graphic usingincludes_graphics
:--- output: pdf_document bibliography: bib.bib --- ```{r setup, include=FALSE} knitr::write_bib(x = "rmarkdown", file = "bib.bib") ``` ```{r, echo = FALSE, fig.cap = "A plot [@R-rmarkdown]"} plot(cars) ```
If this doesn't work (not entirely sure why it doesn't, but some people seem to have problems with the above), you can use text references (see Section 2.2.4 of the bookdown book).
(ref:caption) A plot [@R-rmarkdown] ```{r echo=FALSE, fig.cap="(ref:caption)"} plot(cars) ```
这篇关于如何在带有 rmarkdown 本地引用的图形标题中引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- I also tried