Handling Latex backslashes in xtable

前端 未结 2 1412
暖寄归人
暖寄归人 2020-12-14 16:25

I have a table that includes the following column:

 mytable <- data.frame(beta_0 = c(1,2,3)

What I want to do is output a table with a c

相关标签:
2条回答
  • 2020-12-14 16:38

    Two issues here; first, you need a double backslash as otherwise it treats it as a control sequence. Second, by default, xtable sanitizes text so that it won't break LaTeX. Use one of the sanitize. parameters to control this; to do no sanitizing, pass it the identity function.

    colnames(mytable) <- "$\\beta_0$"
    print(xtable(mytable), include.rownames = F, sanitize.colnames.function = identity)
    
    0 讨论(0)
  • 2020-12-14 16:46

    this is what did the trick for me:

    mat <- round(matrix(c(0.9, 0.89, 200, 0.045, 2.0), c(1, 5)), 4)
    rownames(mat) <- "$y_{t-1}$"
    colnames(mat) <- c("$R^2$", "$\\bar{x}$", "F-stat", "S.E.E", "DW")
    mat <- xtable(mat)
    print(mat, sanitize.text.function = function(x){x})
    

    This way you avoid the backslash issue in the table text.

    0 讨论(0)
提交回复
热议问题