kable/kableExtra将上标添加到group_rows中的组标签 [英] kable/kableExtra Add superscript to group labels in group_rows
问题描述
我有一张要使用kable和kableExtra为pdf演示文稿创建的表.我想对行进行分组,并且需要在行组标签中使用上标.我尝试了几种不同的方法.这是到目前为止我尝试过的一些方法的示例.
I have a table that I am creating for a pdf presentation using kable and kableExtra. I am wanting to group the rows and I need to use superscripts in the row group labels. I have tried several different things. Here is an example of some of the methods I have tried so far.
library(kable)
library(kableExtra)
foo <- data.frame(a = 1:10, b = 11:20, c = 21:30)
kable(foo, format = "latex", booktabs = T, row.names = FALSE, linesep = "", escape = FALSE) %>%
kable_styling(latex_options = c("striped")) %>%
group_rows("Group1<sup>a</sup>", 1, 2) %>%
group_rows(paste0("Group2", footnote_marker_alphabet(1), sep = ""), 3, 4) %>%
group_rows(expression("Group3"^a), 5, 6) %>%
group_rows("Group4\\textsuperscript{a}", 7, 8)
我的想法用光了,无法在搜索中找到任何其他建议.
I have run out of ideas and haven't been able to find any additional suggest in my search.
推荐答案
在group_rows()
调用中需要escape=FALSE
才能解释乳胶命令.您似乎还需要将每个反斜杠加倍(我不太明白为什么).在那之后,有几个可行的选择:
You need escape=FALSE
in your group_rows()
calls to allow the latex commands to be interpreted. You also seem to need to double each backslash (I don't quite understand why). After that, there are a few different options that work:
kable(foo, format = "latex", booktabs = T, row.names = FALSE, linesep = "", escape = FALSE) %>%
kable_styling(latex_options = c("striped")) %>%
group_rows("$\\\\text{Group1}^a$", 1, 2, escape = FALSE) %>%
group_rows(paste0("Group2\\\\", footnote_marker_alphabet(1), sep = ""), 3, 4, escape = FALSE) %>%
# I don't think expression() is helpful, doesn't seem to get converted
# to latex
group_rows(expression("Group3"^a), 5, 6) %>%
group_rows("Group4\\\\textsuperscript{a}", 7, 8, escape = FALSE)
这篇关于kable/kableExtra将上标添加到group_rows中的组标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!