I'm using xtable to compile tables from R automatically while compiling my TeX document. The question I have is how I get the variable names in the table (which in my case are the column names in a dataframe) to be in math mode. I have stored my results in the dataframe adf.results, and essentially what I want is

colnames(adf.results) <- c(" ", "$m^r_t$", "$\delta p_t$",
                           "$R^r_t$", "$R^b_t$", "$y^r_t$")

but that simply inserts $m^r_t$ ... as the column names without interpreting them as being in math mode. Does anyone have a solution?

有帮助吗?

解决方案

as suggested in the xtable gallery vignette you should use a sanitization function (as unikum also suggested). Just some dummy code how I got it working with your example:

library(xtable)
adf.results<-matrix(0,ncol=6,nrow=4)
colnames(adf.results) <- c(" ", "$m^r_t$", "$\\delta p_t$","$R^r_t$", "$R^b_t$", "$y^r_t$")
print(xtable(adf.results),sanitize.text.function=function(x){x})

Good luck with it.

Kind regards,

FM

其他提示

Please see xtable gallery: Sanitization section (page 7 and below).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top