LaTeX math expression in knitr kable (Sweave)

旧巷老猫 提交于 2020-01-13 07:53:09

问题


Is it possible and how to use a LaTeX math expression in a knitr/Sweave report with kable? In the example below, $x^2$ is rendered "as is".

With xtable, for the example below, I would use the option sanitize.colnames.function = function(x) x of print.xtable. Is there such an option for kable?

\documentclass{article}
\usepackage{booktabs}
\begin{document}

<<>>=
library(knitr)
dat <- mtcars[1:5,1:5]
options(knitr.table.format = "latex")
@

<<results='asis'>>=
names(dat)[1] <- "$x^2$"
kable(dat, booktabs=TRUE, caption="My table")
@

\end{document}


回答1:


Yes, use the option escape=FALSE:

kable(dat, booktabs = TRUE, caption = "My table", escape = FALSE)


来源:https://stackoverflow.com/questions/45391566/latex-math-expression-in-knitr-kable-sweave

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