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

如何隐藏flextable页脚的脚注编号并替换为自定义文本?

解决flextable页脚脚注编号的修改问题

方案1:移除页脚处的脚注编号(保留单元格标记)

如果需要保留单元格上的脚注标记(如1、2),但页脚只显示脚注内容、不显示编号,可以分开处理单元格标记和页脚内容:

library(flextable)
library(dplyr)

df = data.frame(col1 = c(123,234,54,5), col2 = c(NA,1,2,3), col3 = 5:8)

df %>%
  flextable() %>%
  # 手动给目标单元格添加上标标记
  compose(i = 1, j = 1,
          value = as_paragraph(
            as_text(col1), " ",
            as_sup("1"), " ",
            as_sup("2")
          )) %>%
  # 添加无编号的页脚内容,colwidths设为表格总列数让内容跨列显示
  add_footer_row(values = as_paragraph("this is a footnote"), colwidths = 3) %>%
  add_footer_row(values = as_paragraph(as_b("Note:"), " This is another footnote"), colwidths = 3) %>%
  # 可选:调整页脚对齐方式和表格样式
  align(part = "footer", align = "left") %>%
  theme_booktabs()

方案2:替换页脚编号为自定义文本

如果需要把默认的数字编号换成自定义文本(如"注1"、"重要提示"),有两种方式:

方式A:直接替换脚注引用符号和页脚文本

这种方式会同时替换单元格上的标记和页脚的编号:

df %>%
  flextable() %>%
  footnote(i = 1, j = 1,
           value = as_paragraph(as_b("注1:"), " this is a footnote"),
           ref_symbols = "注1",
           part = "body") %>%
  footnote(i = 1, j = 1,
           value = as_paragraph(as_b("重要提示:"), " This is another footnote"),
           ref_symbols = "★",
           part = "body") %>%
  theme_booktabs()

方式B:单元格保留原标记,页脚用自定义文本

如果要保留单元格上的数字标记,仅页脚换成自定义文本,同样用compose加标记+add_footer_row加自定义内容:

df %>%
  flextable() %>%
  compose(i = 1, j = 1,
          value = as_paragraph(as_text(col1), " ", as_sup("1"), " ", as_sup("2"))) %>%
  add_footer_row(values = as_paragraph(as_b("注1:"), " this is a footnote"), colwidths = 3) %>%
  add_footer_row(values = as_paragraph(as_b("注2:"), " This is another footnote"), colwidths = 3) %>%
  align(part = "footer", align = "left") %>%
  theme_booktabs()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 20:35:16