Renaming table's column name with Greek letters in kable

只谈情不闲聊 提交于 2021-01-28 21:30:40

问题


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


回答1:


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

It looks a little nicer using booktabs = TRUE:

but you'll need to add

header-includes:
- \usepackage{booktabs}

to the document YAML since you're using beamer.



来源:https://stackoverflow.com/questions/58755431/renaming-tables-column-name-with-greek-letters-in-kable

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