Search code examples
rlatexknitrsweave

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


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


Solution

  • 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:

    enter image description here