Knitr Kable(Sweave)中的LaTeX数学表达式 [英] LaTeX math expression in knitr kable (Sweave)

查看:165
本文介绍了Knitr Kable(Sweave)中的LaTeX数学表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以及如何在带有kable的knitr/Sweave报告中使用LaTeX数学表达式?在下面的示例中,$x^2$是按原样"呈现的.

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".

对于xtable,在下面的示例中,我将使用print.xtable的选项sanitize.colnames.function = function(x) x. kable有这样的选择吗?

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}

推荐答案

是的,请使用选项escape=FALSE:

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

这篇关于Knitr Kable(Sweave)中的LaTeX数学表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆