Simple example of using tables + knitr for latex

后端 未结 2 2008
粉色の甜心
粉色の甜心 2021-01-15 04:11

I\'m struggling with a tables package, all the examples in the packable docs are so complex and none of them works for me with knitr and latex. Could somebody h

2条回答
  •  时光取名叫无心
    2021-01-15 05:05

    I don't think that this is possible with RMarkdown if you want the table to be in LaTeX style. However, you can easily do this with the xtable package when you write your code in an .Rnw file:

    \documentclass{article}
    \begin{document}
    <<>>=
    library("xtable")
    df <- data.frame(matrix(1:9, nrow = 3))
    colnames(df) <- c("first column", "second $\\frac{1}{2}$",
                      "third column")
    @
    <>=
    print(xtable(df), floating = TRUE,
          sanitize.colnames.function = identity, type = "latex")
    @
    \end{document}
    

提交回复
热议问题