gpt4 book ai didi

r - 如何在带有 rmarkdown 本地引用的图形标题中引用?

转载 作者:行者123 更新时间:2023-12-04 03:02:34 25 4
gpt4 key购买 nike

在 R Markdown 中,我想要一个带有 R Markdown 原生引文样式的链接引文的图形标题 [@ref] .但是,当我插入 [@hawking_thermodynamics_1983] 时最后的片段到标题中,它只是抛出一个错误:

! 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

使用此输出:

enter image description here

我希望括号中的引文出现在图标题内,并带有引用书目的工作链接。引用书目应该像往常一样自动出现。

我怎么可能做到这一点?

备注:
  • 我也试过 \[@...或没有括号但没有用。
  • 我也试过这个 \caption{Captiontextfoo \cite{[@hawking_thermodynamics_1983]}}来自 this answer ,但效果不佳,仅显示 [?] .
  • R 版本 3.4.3 (2017-11-30)
  • 平台:x86_64-w64-mingw32/x64(64位)
  • 运行于:Windows 7 x64 (build 7601) Service Pack 1
  • 最佳答案

    此问题似乎已修复,可以直接在 fig.cap 中包含引文争论:

    这是一个创建 bib.bib 的最小示例文件在与 .Rmd 相同的目录中文件。它还包括使用 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)
    ```

    enter image description here

    如果这不起作用(不完全确定为什么不起作用,但有些人似乎对上述问题有疑问),您可以使用文本引用(请参阅 Section 2.2.4 of the bookdown book )。
    (ref:caption) A plot [@R-rmarkdown]

    ```{r echo=FALSE, fig.cap="(ref:caption)"}
    plot(cars)
    ```

    关于r - 如何在带有 rmarkdown 本地引用的图形标题中引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47860390/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com