在 R flextable 中,复杂的符号可以出现在列标题中

In R flextable can complex symbols appear in column headings

使用 flextable 制作 table,我希望列标题为 pi(带帽子)和 i 下标。使用 flextable 6 I see,我可以使用 compose() 函数为标题添加基本格式。我可以轻松获得 pi sub i,但我不知道如何将帽子放在 pi 上。

test <- data.frame(hat_pi_i= c(0.1, 0.9))

# devtools::install_github("davidgohel/flextable")  # version 6.x
# devtools::install_github("davidgohel/officer")  # for flextable 6 to work

library(flextable)
# compose conflicts with purrr & igraph
flextable(test) %>% 
  compose(part = "header", j = "hat_pi_i", 
          value = as_paragraph("hat π", as_sub("i"))) 

是否可以调整上面的标题,将帽子放在 pi 上而不是旁边的单词?

有一种骇人听闻的方法:

flextable(test) %>% 
  compose(part = "header", j = "hat_pi_i", 
          value = as_paragraph("\U1D70B\U0302", as_sub("i"))) 

这使用 Unicode 字符:\U1D70B 是数学样式 pi,\U0302 表示在前一个字符上加上抑扬符。您也可以使用 π 来处理第一个字符,但它看起来不太好,因为(至少在我的系统上)抑扬音最终放错了位置: