How do I print superscripts in a table using xtable and sweave?

為{幸葍}努か 提交于 2019-12-06 04:15:58

问题


So my problem statement is as follows : I have defined a data frame in my Sweave document (.Rnw extension) using the following code:

<<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?


回答1:


The actual superscript is quite easy. \\textsuperscript{1} in conjunction with sanitize.text.function = identity will get you there.

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.

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


来源:https://stackoverflow.com/questions/26525879/how-do-i-print-superscripts-in-a-table-using-xtable-and-sweave

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!