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
在编译我的TeX文档时,我正在使用xtable自动编译R中的表。我的问题是如何将表中的变量名称(在我的情况下是数据帧中的列名称)置于数学模式中。我已将结果存储在数据框adf.results中,基本上我想要的是
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?
但这只是插入$ m ^ r_t $ ...作为列名而不将它们解释为数学模式。有没有人有办法解决吗?
2 个解决方案
#1
30
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:
正如xtable gallery vignette中建议的那样,你应该使用一个清理功能(如unikum也建议的那样)。只是一些虚拟代码我如何使用你的例子:
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
调频
#2
5
Please see xtable gallery: Sanitization section (page 7 and below).
请参阅xtable gallery:Sanitization部分(第7页及以下)。
#1
30
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:
正如xtable gallery vignette中建议的那样,你应该使用一个清理功能(如unikum也建议的那样)。只是一些虚拟代码我如何使用你的例子:
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
调频
#2
5
Please see xtable gallery: Sanitization section (page 7 and below).
请参阅xtable gallery:Sanitization部分(第7页及以下)。