1

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

Dayne
  • 463
  • 3
  • 12

2 Answers2

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:

enter image description here

Prem
  • 11,775
  • 1
  • 19
  • 33
0

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)))

enter image description here

Rafael Díaz
  • 2,134
  • 2
  • 16
  • 32
  • Thanks! But since I am making a more complex table I want to stick to kable(). I have edited the question as the initial problem is solved but now I am facing some other issue. – Dayne May 07 '18 at 02:34