[英]How do I print superscripts in a table using xtable and sweave?
So my problem statement is as follows : I have defined a data frame in my Sweave document (.Rnw extension) using the following code: 所以我的问题陈述如下:我使用以下代码在我的Sweave文档(.Rnw扩展名)中定义了一个数据框:
<<label=table2_1,echo=FALSE>>=
table2_1_rows <- c('Students with compulsory Evaluations',
'Teachers with compulsory evaluations1',
'Teachers without Evaluation2',
'Students without compulsory evaluations3'
)
table2_1_data <- c(1,2,3,4)
table2_1final <- data.frame(table2_1_rows,table2_1_data)
@
<<label=tab1,echo=FALSE,results=tex>>=
print(xtable(table2_1final,caption= ' ',align="|c|c|c|c|c|c|"),include.rownames=FALSE)
@
How do I make xtable print the numbers 1,2,3 (following the word Evaluation) as superscripts? 如何使xtable打印数字1,2,3(在评估一词后面)作为上标?
The actual superscript is quite easy. 实际的上标非常简单。 \\\\textsuperscript{1}
in conjunction with sanitize.text.function = identity
will get you there. \\\\textsuperscript{1}
与sanitize.text.function = identity
一起将带你到那里。
I had to make some other changes to your example. 我不得不对你的例子做一些其他修改。 There are too many columns in align and the underscores in the variable names cause problems compiling tex. 对齐的列太多,变量名中的下划线会导致编译tex的问题。
<<label=table2_1,echo=FALSE>>=
require(xtable)
table2_1_rows <- c('Students with compulsory Evaluations',
'Teachers with compulsory evaluations\\textsuperscript{1}',
'Teachers without Evaluation\\textsuperscript{2}',
'Students without compulsory evaluations\\textsuperscript{3}'
)
table2_1_data <- c(1,2,3,4)
table2_1final <- data.frame(table2_1_rows,table2_1_data)
names(table2_1final) <- c("rows", "data")
@
<<label=tab1,echo=FALSE,results=tex>>=
print(xtable(table2_1final,caption= ' ',align="|c|c|c|"),include.rownames=FALSE,
sanitize.text.function = identity)
@
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.