在图和表的标题中。当使用 knitr::kable()
渲染时,表格标题中对其他图形/表格的引用可以正常工作,但使用
kableExtra::kbl()
渲染时则不行。但我喜欢kableExtra
中的一些额外内容。有没有办法让表格标题中的参考文献适用于
kableExtra
?在最初的帖子后添加了评论:
我正在渲染为 PDF。就在此时,我尝试渲染为 HTML,一切正常。因此,渲染为 PDF 时出现了问题。
下面附加了带有最小示例的完整 .qmd 文档,但这里是重点内容。已经显示了一个简单的图形,由 @fig-A
d_mat
。当我使用
knitr::kable()
将矩阵显示为表格时,标题中的引用将解析为“图 1”,如下所示:
#| echo: FALSE
#| label: tbl-kable
#| tbl-cap: "This is a table with `knitr::kable()`. Compare with @fig-A."
knitr::kable( d_mat )
但是当我使用 kableExtra::kbl()
not
解析的,如下所示:
#| echo: FALSE
#| label: tbl-kbl
#| tbl-cap: "This is a table with `kableExtra::kbl()`. Compare with @fig-A."
kableExtra::kbl( d_mat )
完整的.qmd文档:
---
title: "Table Test"
---
```{r}
#| echo: FALSE
#| label: fig-A
#| fig-cap: "This is a figure. Compare with @tbl-kable."
#| fig-pos: "!tbph" # for LaTeX floating figures
plot( 0 , 0 )
```
```{r}
#| echo: FALSE
d_mat <- matrix( 1:12 , nrow=3 ,
dimnames=list( Rows=c("R1","R2","R3"),
Columns=c("C1","C2","C3","C4") ) )
```
```{r}
#| echo: FALSE
#| label: tbl-kable
#| tbl-cap: "This is a table with `knitr::kable()`. Compare with @fig-A."
knitr::kable( d_mat )
```
```{r}
#| echo: FALSE
#| label: tbl-kbl
#| tbl-cap: "This is a table with `kableExtra::kbl()`. Compare with @fig-A."
kableExtra::kbl( d_mat )
```
**The caption of @fig-A resolves the reference to the table.**
**The caption of using `knitr::kable` in @tbl-kable resolves the reference to the figure.**
**The caption of using `kableExtra::kbl` in @tbl-kbl does *not* resolve the reference to the figure.**
答案只是评论的延伸。所有源文件/日志均可在