如何在 kableExtra 脚注中引用参考文献?

How to cite a reference in kableExtra footnote?

我正在写一个 R Markdown 文档,其中有一个 table。在这个 table 的脚注中,我想引用一位作者。但是,在这种情况下使用 @citationkey 不起作用。

有人知道怎么做吗?

这是一个可重现的例子(我在 kableExtra 中包含了所有需要的 LaTeX 包,但其中一些可能在这里是不必要的):

---
title: "Untitled"
author: ""
date: ""
output: 
  bookdown::pdf_document2
bibliography: refs.bib
toc: false
header-includes:
  - \usepackage[utf8]{inputenc}
  - \usepackage[T1]{fontenc}
  - \usepackage{booktabs}
  - \usepackage{longtable}
  - \usepackage{array}
  - \usepackage{multirow}
  - \usepackage{wrapfig}
  - \usepackage{float}
  - \usepackage{colortbl}
  - \usepackage{pdflscape}
  - \usepackage{tabu}
  - \usepackage{threeparttable}
  - \usepackage{threeparttablex}
  - \usepackage[normalem]{ulem}
  - \usepackage{makecell}
  - \usepackage{xcolor}
---

Here, I can cite @abel2018.

```{r}
library(kableExtra)

kable(head(mtcars)) %>%
  footnote(general = paste0("A footnote in which I would like to cite @abel2018."))
```

# References {-}

以及refs.bib中的引用:

@article{abel2018,
  title = {Estimates of {{Global Bilateral Migration Flows}} by {{Gender}} between 1960 and 2015},
  author = {Abel, Guy J.},
  date = {2018-09},
  journaltitle = {International Migration Review},
  shortjournal = {International Migration Review},
  volume = {52},
  pages = {809--852},
  doi = {10.1111/imre.12327},
  url = {http://journals.sagepub.com/doi/10.1111/imre.12327},
  urldate = {2019-12-14},
  langid = {english},
  number = {3}
}

您的方法的问题在于 paste() 无法识别密钥,而只是将其视为文本。

要写入 HTML,可以使用 knitr::asis_output("@abel2018")

不幸的是,这不适用于 bookdown。 但是,您可以使用 bookdown:

中记录的文本参考

The syntax for a text reference is (ref:label) text, where label is a unique label throughout the document for text. It must be in a separate paragraph with empty lines above and below it. The paragraph must not be wrapped into multiple lines, and should not end with a white space.

Then you can use (ref:foo) in your figure/table captions

例如:

(ref:abel-citation) @abel2018 

```{r}
library("kableExtra")

kable(mtcars) %>%
    footnote(general = paste0("A footnote in which I would like to cite (ref:abel-citation)"))
```