How to print table labels using xtable and sweave?

So my problem is this: I defined a data frame in a Sweave document (extension .Rnw) 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 to make xxtable print numbers 1,2,3 (after the word Evaluation) as superscripts?

+4
source share
1 answer

The actual superscript is pretty simple. \\textsuperscript{1}combined with sanitize.text.function = identitytakes you there.

I had to make some other changes to your example. Too many columns are aligned, and underscores in variable names cause tex compilation problems.

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

All Articles