Indenting disturbed when adding superscript to rowname of a grouped row using kable in latex

ぃ、小莉子 提交于 2021-02-10 15:07:28

问题


How do I add superscript to name of a particular row of a table created using kable in latex environment (this link gives solution for markdown). I tried following:

at2=cbind(1:5,6:10,11:15)
rownames(at2)=c("one", "two", "three", "four$^1$", "five")
kable(at2,format = "latex",booktabs=T)

But this isn't working.

For image of result click this

EDIT: The first problem is solved with escape = FALSE but now a new problem related to indentation has come up. I am using group_rows which automatically creates indenting. Using escape is creating problem with this indenting. Code:

at2=cbind(1:5,6:10,11:15)
rownames(at2)=c("one", "two", "three", "four$^1$", "five")
kable(at2,format = "latex",booktabs=T,escape = FALSE,col.names = month.abb[1:3])%>%
 group_rows("group1",1,2)%>%
 group_rows("group2",3,5)

New Result image


回答1:


In order to add superscript footnote_marker_number should be handy

library(knitr)
library(kableExtra)
library(dplyr)

#sample data
at2 <- cbind(1:5, 6:10, 11:15)
rownames(at2) <- c("one", "two", "three", paste0("four", footnote_marker_number(1, "latex")), "five")

kable(at2, format = "latex", escape = F, col.names = month.abb[1:3]) %>%
  group_rows("group1", 1, 2) %>%
  group_rows("group2", 3, 5)

Output is:




回答2:


I do not usually use kable, but I found a solution to your problem with the xtable package.

library(xtable)
print(xtable(at2, auto = T), type='latex', sanitize.text.function=identity,
 comment=FALSE, include.colnames = F,hline.after = c(0,nrow(at2)))



来源:https://stackoverflow.com/questions/50185857/indenting-disturbed-when-adding-superscript-to-rowname-of-a-grouped-row-using-ka

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!