如何在 Bookdown 中放置交叉引用?

How to put a crossreference in Rbookdown?

我不确定我是否理解 documentation

中的这一部分

the table label for a code chunk with the label foo will be tab:foo

假设我有一个 RMarkdown 块,例如

```{r mytable, echo=FALSE}
kable(df, booktabs=T)
```

我会考虑 mytabel 作为代码块的标签。这意味着我应该能够输入如下所示的叙述:

这是我的 table \@ref(tab:mytable)

并且 \@ref 应该引用 table 数字而不是 chucnk id。相反,我得到了一个双(和可点击)??。我做错了什么?

documention的第二段中:

Like figures, tables with captions will also be numbered and can be referenced.

所以你想交叉引用 table,你必须指定 caption 参数。

您可以创建一个空的 RStudio 项目和/或将以下代码保存为 index.Rmd 文件。或下载 https://github.com/yihui/bookdown-minimal 并用以下代码替换 index.Rmd 文件的内容。然后你可以在 Build 面板中按 Build Book 按钮。

---
title: "A Book"
author: "Frida Gomam"
site: bookdown::bookdown_site
output:
  bookdown::gitbook: default
---

# reference

This is my table \@ref(tab:mytable)

# table

```{r mytable, echo=TRUE}
knitr::kable(iris[1:10, ], booktabs=T, caption='A table of the first 10 rows of the mtcars data')
```