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

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

问题描述

在编译我的 TeX 文档时,我正在使用 xtable 自动从 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 vignette 你应该使用清理功能(正如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})

祝你好运.

亲切的问候,

调频

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

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