[英]RMarkdown: cannot reference the label of a `knitr::kable` table
我在 r markdown 文件中引用knit::kable
表的 label 時遇到問題。
這是此錯誤的最小重現。 這是我的 r markdown 文件:
---
output:
pdf_document:
number_sections: yes
tables: true
---
Trying to reference Table \ref{some_label}.
```{r}
df <- data.frame(
x1 = c(1,2,3),
x2 = c(4,5,6)
)
df |> knitr::kable(
digits = 3,
label = "some_label"
)
```
如您所見,我得到了 Table??
任何人都知道是什么原因造成的? 我怎樣才能解決這個問題?
Latex 需要知道它可以用哪個數字引用 object,因此您只能引用有標題的表格。
---
output:
pdf_document:
number_sections: yes
keep_tex: true
tables: true
---
Trying to reference Table \ref{somelabel}.
```{r}
df <- data.frame(
x1 = c(1,2,3),
x2 = c(4,5,6)
)
df |> knitr::kable(
digits = 3,
caption = "This is the table caption\\label{somelabel}",
)
```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.