r-markdown - R Markdown - 交叉引用没有“kable”的HTML表格
问题描述
Rmarkdown 文档中有关表格交叉引用的所有问题都需要使用kable
交叉引用。如何交叉引用不是由 生成的 HTML 表kable
?例如,使用table1
包:
---
title: Test Table Cross-Reference
output: bookdown::html_document2
---
This should be a cross reference to table \@ref(tab:table).
```{r table, echo = FALSE}
table1::table1(~depth + table + price | cut, data = ggplot2::diamonds)
```
解决方案
这不像使用 kable 那样简单,其中 knitr 会自动创建链接和引用,并将两者插入最终的 HTML 文档中。但是,如果您可以在没有自动编号的情况下生活,则很容易自己创建链接。
您可以使用 HTML 创建标题,通过参数锚定它id
,然后像这样链接到该锚点(这类似于 knitr 自动执行的操作):
This should be a cross reference to table [1](#tab:table)
```{r table2, echo = FALSE}
table1::table1(~depth + table + price | cut, data = ggplot2::diamonds)
```
<center><p id='tab:table'> Table 1: Your Caption</p></center>
请注意,table1::table1()
还有一个选项caption
,您可以将字符串传递给该选项,因此也可以使用类似的方法:
```{r table2, echo = FALSE}
table1::table1(~depth + table + price | cut, data = ggplot2::diamonds,
caption = "<p id='tab:table'> Table 1: Your Caption</p>")
```
推荐阅读
- android-jetpack-compose - 在循环中重新组合多个 Composable
- azure-logic-apps - 电源自动化 - 自定义连接器 - 具有动态架构属性的 Webhook 触发器
- php - 如何在 Prestashop 模块中使用用户定义的模板发送电子邮件
- android - Kotlin Flow 最佳实践
- python-3.x - 在 python 中使用 Regex 将 $$ 或更多替换为单个空格
- mysql - MySql Binlog 更新语句 where 子句具有所有表列,即使客户端在运行查询时在 where 子句中仅使用主键
- python - 如何使用 statsmodels.formula.api logit 进行预测
- spring-boot - 如何在 Spring Boot 中使用 JUNIT5 和 mockito 为代码编写 DAO 类的测试用例
- javascript - React 中的 iframe 给出了太多的直接问题
- node.js - 部署heroku时的socket.io错误