简体   繁体   English

使用带有R和Latex的xtable,列名中的数学模式?

[英]Using xtable with R and Latex, math mode in column names?

I'm using xtable to compile tables from R automatically while compiling my TeX document. 我正在使用xtable在编译我的TeX文档时自动从R编译表。 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 我已将结果存储在数据框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. 但这只是插入$m^r_t$ ...作为列名而不将它们解释为处于数学模式。 Does anyone have a solution? 有没有人有办法解决吗?

as suggested in the xtable gallery vignette you should use a sanitization function (as unikum also suggested). 正如xtable gallery vignette中建议的那样,你应该使用一个清理功能(如同unikum一样)。 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 调频

请参阅xtable gallerySanitization部分(第7页及以下)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM