kableExtra:: LaTeX commands are not rendering properly in add_header_above

264 Views Asked by At

I want to use LaTeX commands in add_header_above function of kableExtra

library(kableExtra)

x1 <- knitr::kable(head(mtcars), "html")
add_header_above(x1, c(" ", "Group 1" = 5, "Group 2" = 6))
add_header_above(x1, c(" ", "\\alpha" = 5, "Group 2" = 6))

x2 <- knitr::kable(head(mtcars), "latex")
add_header_above(x2, c(" ", "Group 1" = 5, "Group 2" = 6))
add_header_above(x2, c(" ", "\\alpha" = 5, "Group 2" = 6))

However, the LaTeX command \\alpha is not rendering properly. Any solution, please.

Edited

Test2 <- c(" ", مواطنين = "5", `غير مواطنين` = "6")
Test3 <- c(`\textarabic{}` = " ", `\textarabic{مواطنين}` = "5", 
`\textarabic{غير مواطنين}` = "6")

add_header_above(x1, Test2, escape = FALSE)

add_header_above(x1, Test3, escape = FALSE)
1

There are 1 best solutions below

1
s_baldur On BEST ANSWER

You can use escape = FALSE:

add_header_above(x2, c(" ", "$\\\\alpha$" = 5, "Group 2" = 6), escape = FALSE)

enter image description here