Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a Percent Symbol in an xtable caption using Sweave in R

I'm trying to use Sweave to generate a statistical report, and am trying to put a caption on an xtable, however if I include the percent symbol this breaks things.

Some example code

<<label=Analyte2_Results, results=tex, echo=FALSE>>=
    print(xtable(result[[2]], caption=paste(levels(vardata$Analyte)[1],
                            " percent bias and precision estimates with 95 \% confidence intervals",sep="")),
            tabular.environment='longtable',
            latex.environments=c("center"), 
            floating=FALSE, 
            include.rownames=FALSE)
@

If I use % or \% then the Sweave process works but Latex doesn't, if I try \% then Sweave fails. There doesn't seem to be an alternative way to specify a percent symbol in Latex

Is there a way to actually put a Percent symbol in the caption ?

like image 997
PaulHurleyuk Avatar asked Jul 14 '10 13:07

PaulHurleyuk


1 Answers

Try "escaping" the "escape" operator, so that it survives Sweaving to make it to the LaTeX file (i.e., \\%). This is because in LaTeX the "%" needs an escape operator "\". For example, when I was naming some table rows and columns recently I had to use:

row.names(table.a) <- c("ARCH(1)", "~")
colnames(table.a) <- c("$\\omega$", "$\\alpha_{1}$", "Q(1)", "Q(12)")
like image 131
Richard Herron Avatar answered Sep 25 '22 08:09

Richard Herron