如何在带有rmarkdown本机引用的图形标题中引用? [英] How to cite within a figure caption w/ rmarkdown native citation?
问题描述
在R Markdown中,我想要带有R Markdown本机引用样式[@ref]
的链接引用的图形标题.但是,当我在标题的末尾插入[@hawking_thermodynamics_1983]
代码段时,它只会引发错误:
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
示例:
这是我的代码:
---
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
\begin{figure}[h]
\centering
\includegraphics[width=13cm]{example.jpg}
\caption{Captiontextfoo}\label{fig1}
\end{figure}
[@hawking_thermodynamics_1983]
# Bibliography
具有以下输出:
我希望括号内的引用出现在图形标题中,并带有指向书目的有效链接.书目应该像往常一样自动出现.
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?
注释:
- 我也尝试了
\[@...
或没有括号,但是没有用. - 我也在此答案中尝试了此
\caption{Captiontextfoo \cite{[@hawking_thermodynamics_1983]}}
,但效果不佳,仅显示. - R版本3.4.3(2017-11-30)
- 平台:x86_64-w64-mingw32/x64(64位)
- 在以下环境中运行:Windows 7 x64(内部版本7601)Service Pack 1
- 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
推荐答案
此问题似乎已解决,可以直接在fig.cap
参数中包含引用:
This problem appears to be fixed, and the citation can be included directly within the fig.cap
argument:
这是一个最小示例,该示例在与.Rmd
文件相同的目录中创建一个bib.bib
文件.它还包括使用includes_graphics
的图形:
Here is a minimal example which creates an bib.bib
file in the same directory as the .Rmd
file. It also includes the graphic using includes_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本机引用的图形标题中引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!