Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming table's column name with Greek letters in kable

I am creating presentation using R Markdown with PDF (Beamer) as output. I am using library kableExtra for some formatting.

The following code gives me the expected result

library(knitr)
# library(kableExtra)

# create data frame
df <- data.frame(mean = c(1,2,3), beta = c(5,6,7))

# print data frame to slide
knitr::kable(df,
  col.names = c("mean", "$\\beta_t$")) 

However, when I use library(kableExtra) as in code below, the printed PDF show $\beta_t$ instead of the Greek letter beta.

library(knitr)
library(kableExtra)

# create data frame
df <- data.frame(mean = c(1,2,3), beta = c(5,6,7))

# print data frame to slide
knitr::kable(df,
  col.names = c("mean", "$\\beta_t$")) 

Is there any good way to rename the column name to Greek letter while using library(kableExtra)?

like image 642
U_ng Avatar asked Oct 26 '25 19:10

U_ng


1 Answers

Use escape = FALSE in the call to kable():

# print data frame to slide
knitr::kable(df,
  col.names = c("mean", "$\\beta_t$"),
  escape = FALSE) 

This produces

screenshot

It looks a little nicer using booktabs = TRUE:

screenshot

but you'll need to add

header-includes:
- \usepackage{booktabs}

to the document YAML since you're using beamer.

like image 156
user2554330 Avatar answered Oct 28 '25 10:10

user2554330