You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R Markdown表格交叉引用失效,渲染后显示“??”求助

解决R Markdown表格交叉引用显示“??”的问题

核心问题原因

你使用bookdown的输出格式(html_document2/pdf_document2)支持交叉引用,但当前表格代码缺少必要的标题(caption)配置,导致bookdown无法识别表格并生成对应引用编号。

修复步骤

  • 给kable()函数添加caption参数,定义表格标题
  • 确保代码块名称(示例中为test)和交叉引用的tab:test保持一致

修改后的完整代码

---
title: "reproducible example"
date: "2023-04-13"
output:
  bookdown::html_document2: default
  bookdown::pdf_document2: default
---

My reference \@ref(tab:test)

```{r test, echo=FALSE}
library(tidyverse)
kableExtra::kable(
  tibble(variable= "hello", another = "bye"),
  caption = "测试表格"  # 必须添加该参数
)
## 额外说明
- 若使用`kableExtra`的扩展功能(如`kable_styling()`),只需将`kable()`的输出传入后续函数即可,`caption`参数保留在`kable()`中
- 确保`bookdown`包为最新版本,避免版本兼容问题

内容的提问来源于stack exchange,提问作者Jan Pfänder
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 09:24:55