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_orderwithnotation = "alphabet"—this is the officialkableExtraparameter for setting footnote marker styles. - Column Superscripts: We added LaTeX superscript syntax (
$^{a}$) to the column names. Settingescape = FALSEinkable()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. Theescape = FALSEsetting ensures the formula is rendered correctly.
Notes
- Ensure you have the latest version of
kableExtrainstalled, 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
相关产品推荐
相关产品推荐

