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

R Markdown中kable表格添加带公式的字母脚注及上标报错求助

Fixing Footnote Issues in kableExtra

First, the error you're seeing comes from using an invalid argument name—footnote_order isn't recognized by add_footnote(). The correct parameter to specify footnote marker type is notation.

Here's how to meet all your requirements: add alphabetic footnotes with math formulas, and display superscript markers next to var_a and var_b:

Step-by-Step Corrected Code

library(kableExtra)

# Create your data frame
var_a <- rep(0, 3)
var_b <- rep(1,3)
var_c <- rep(2, 3)

# Modify column names to include LaTeX superscripts for footnotes
df <- data.frame(
  `var_a$^{a}$` = var_a,  # Superscript 'a' for var_a
  `var_b$^{b}$` = var_b,  # Superscript 'b' for var_b
  var_c = var_c
)

# Generate the table with footnotes
kable(df, "latex", caption = "Title", booktabs = TRUE, escape = FALSE) %>% 
  kable_styling() %>% 
  add_footnote(
    c(
      "Standard errors in parenthesis. P-values in brackets.",
      "P-values from Wald-test for $H_0$: Hazard Ratio = 1."
    ),
    notation = "alphabet"  # Use alphabetic markers (a, b, etc.)
  )

Key Fixes & Explanations

  • Corrected Argument Name: Replaced footnote_order with notation = "alphabet"—this is the official kableExtra parameter for setting footnote marker styles.
  • Column Superscripts: We added LaTeX superscript syntax ($^{a}$) to the column names. Setting escape = FALSE in kable() ensures LaTeX renders these superscripts instead of displaying raw code.
  • Math Formulas in Footnotes: LaTeX math syntax ($H_0$) works seamlessly in footnotes when using LaTeX output. The escape = FALSE setting ensures the formula is rendered correctly.

Notes

  • Ensure you have the latest version of kableExtra installed, as parameter names can change between versions.
  • If knitting to HTML instead of PDF, swap the LaTeX superscript syntax with HTML (<sup>a</sup>), but your code specifies "latex" output so the above works perfectly for PDF rendering.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.06 13:42:36