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

R Quarto中使用modelsummary时表格交叉引用失效求助

Quarto中modelsummary表格交叉引用失效问题修复

问题现象

在Quarto渲染PDF文档时,使用modelsummary包生成的回归表格无法正常完成交叉引用,引用位置显示为?@tbl-test,无法关联到对应表格的编号。

复现代码

YAML配置

---
title: "Untitled"
editor: visual
format: pdf
fontfamily: libertinus
pdf-engine: pdflatex
documentclass: article
number-sections: true
toc: true
toccolor: blue
csl: american-political-science-association.csl
link-citations: true
execute: 
  echo: false
  warning: false
bibliography: referencesQM.bib
fig-cap-location: top
fig-pos: "H"
lang: en
fontsize: 12pt
linestretch: 1.5
geometry: left=2.5cm, right=2.5cm, top=3cm, bottom=3cm
lof: true
lofcolor: blue
lot: true 
lotcolor: blue
---

R代码

library(modelsummary)

Height <- c(156,176,178, 187,203,198,145,167,187,186)
Weight <- c(79,65,76,123,59,76,89,78,101,58)
Happiness <- c(1,5,7,10,3,5,3,6,8,7)

Dataset <- data.frame(Height, Weight, Happiness)

Simplelm <- lm(Happiness~Height+Weight, data = Dataset)

引用测试:@tbl-test

原错误代码块:

#| label: tbl-test, 
#| tbl-cap: "Test"
modelsummary(Simplelm)

解决方案

修改表格对应的代码块选项,删除label行末尾的逗号:

#| label: tbl-test
#| tbl-cap: "Test"
modelsummary(Simplelm)

原因说明

Quarto的代码块元数据选项不允许在键值对末尾添加逗号,这个语法错误会导致Quarto无法正确识别表格的label属性,进而无法建立交叉引用的关联关系,最终出现?@tbl-test的未解析引用提示。

额外注意:

  • 使用完整的Quarto渲染流程(如quarto render命令或RStudio中的渲染按钮),避免缓存残留导致的问题;
  • modelsummary在Quarto环境下默认会输出符合交叉引用要求的表格格式,无需额外配置输出类型。

内容的提问来源于stack exchange,提问作者ThomasKlein

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 03:47:10