代码之家  ›  专栏  ›  技术社区  ›  Stéphane Laurent

knitr kable(Sweave)中的LaTeX数学表达式

  •  13
  • Stéphane Laurent  · 技术社区  · 7 年前

    kable $x^2$ 按“原样”呈现。

    xtable ,对于下面的示例,我将使用该选项 sanitize.colnames.function = function(x) x 属于 print.xtable 卡布尔

    \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}
    

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  16
  •   Stéphane Laurent    7 年前

    是的,使用该选项 escape=FALSE

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