【问题标题】:Citing inside the cell of flextable在 flextable 的单元格内引用
【发布时间】:2026-01-29 00:00:01
【问题描述】:

我正在尝试使用 rmarkdown 和 flextable 创建一个表格,我在其中引用了各种作品。

我的 Rmakrdown 文件:

---
title: "Innovative title"
author: "Vag Vaf"
date: '2021-12-29'
bibliography: references.bib
csl: apa-6th-edition.csl
output:
  bookdown::word_document2:
    fig_caption: yes
  pdf_document:
    toc: true
    toc_depth: 2
    citation_package: natbib
    keep_tex: true
    extra_dependencies: rotating, bookmark
  fontsize: 12pt
  geometry: margin=1in
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(fig.retina = 3, warning = FALSE, message = FALSE)
```

```{r studies-table}
studies.table <- tibble (
  Authors = c("@Author1",
              "@Author2"),
  Area = c("Area1",
           "Area2")
    )
ft <- flextable(studies.table)
```

在我的references.bib中:

@article{Author1,
author = {Author, Solo},
journal = {Journal of Reproducible Examples},
pages = {1--18},
title = {{Yet another Test Title}},
volume = {1},
year = {2022}
}
@article{Author2,
author = {Author, Two and Author, Four},
journal = {Journal of Reproducible Examples},
pages = {75--82},
title = {{Awesome title}},
volume = {1},
year = {2022}
}

我正在尝试使用此代码,但 @Author1 和 @Author2 未转换为实际引用。它们在表中显示为@Aurthor1@Author2。有什么方法可以表明应该将其转换为引用?

【问题讨论】:

  • 你能提供一个最小的可重复的例子(包括引用)吗?
  • @Maël:根据要求更新

标签: r r-markdown knitr pandoc flextable


【解决方案1】:

markdown 语法在灵活表格单元格中工作需要 ftExtra 包:

```{r setup, include=FALSE}
library(easypackages)
packages(
  "tidyverse",
  "flextable",
  "ftExtra"
)
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(fig.retina = 3, warning = FALSE, message = FALSE)
```

```{r studies-table}
studies.table <- tibble(
  Authors = c(
    "@Author1",
    "@Author2"
  ),
  Area = c(
    "Area1",
    "Area2"
  )
)
flextable(studies.table) %>%
  ftExtra::colformat_md()
```

【讨论】:

    最近更新 更多