在R和Latex中使用xtable,在列名中使用数学模式吗? [英] Using xtable with R and Latex, math mode in column names?

查看:178
本文介绍了在R和Latex中使用xtable,在列名中使用数学模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xtable在编译TeX文档时自动从R编译表.我的问题是如何将表中的变量名(在我的情况下是数据帧中的列名)设置为数学模式.我将结果存储在adf.results数据框中,基本上我想要的是

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$")

,但这只是将$m^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?

推荐答案

,如 xtable gallery 小插图,您应该使用清理功能(也建议使用unikum). 只是一些伪代码,我如何将其与您的示例一起使用:

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})

祝你好运.

亲切的问候,

FM

这篇关于在R和Latex中使用xtable,在列名中使用数学模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆