如何调整gt表格脚注的显示顺序至自定义排列?
调整gt表格脚注顺序的实现方法
我为gt表格编写了如下脚注代码:
tab_footnote( footnote = "In cell comment", locations = cells_body(columns = 1, rows = 2) ) |> opt_footnote_marks(marks = "letters") |> tab_footnote( footnote = md("*Notes:* Robust standard errors are in parentheses.") ) |> tab_footnote( footnote = "+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001." )
gt默认的脚注显示顺序为:无指定标记的脚注在前,带标记的脚注在后,实际显示效果如下:
Notes: Robust standard errors are in parentheses. + p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001. ^a in cell comment.
我希望将脚注调整为如下排列顺序:
Notes: Robust standard errors are in parentheses. ^a in cell comment. + p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001.
解决方案
通过给最后一个脚注指定标记类型,并调整脚注的显示顺序即可实现需求。修改后的代码如下:
tab_footnote( footnote = "In cell comment", locations = cells_body(columns = 1, rows = 2) ) |> opt_footnote_marks(marks = "letters") |> tab_footnote( footnote = md("*Notes:* Robust standard errors are in parentheses.") ) |> tab_footnote( footnote = "+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001.", mark = "symbol" # 为显著性说明脚注指定符号类标记 ) |> opt_footnote_order(order = c("unnumbered", "letter", "symbol")) # 设置脚注的显示顺序
说明
mark = "symbol":给原本无标记的显著性说明脚注指定一个标记类型(符号类),使其与第一个无标记脚注区分开opt_footnote_order(order = c("unnumbered", "letter", "symbol")):明确指定脚注的显示优先级,先显示无标记脚注,再显示字母标记脚注,最后显示符号类标记脚注,从而实现目标顺序
内容的提问来源于stack exchange,提问作者Zach
相关产品推荐
相关产品推荐

