[R] Sweave, xtable plus/minus sign

Ottorino-Luca Pantani ottorino-luca.pantani at unifi.it
Tue Jun 29 18:01:15 CEST 2010


On 29/06/2010 17:36, Marc Schwartz wrote:
> On Jun 29, 2010, at 10:08 AM, Ottorino-Luca Pantani wrote:
>
>    
> ................
>> paste("$\\pm$", 1.34, sep="")
>>      
> [1] "$\\pm$1.34"
>
>
> I believe you then need to tweak the sanitize.text.function argument in print.xtable() to properly handle the backslashes.
>
> HTH,
>
> Marc Schwartz
>
>
>    
Thanks, Marc.
I modified the code as follows:

foo.df$Std.Dev <-
                  paste("$\\pm$", round(mySD,2), sep="")
tmpTable <-
            xtable(foo.df, caption ="Simulated data",
                   label="tab:five", digits=2)
print(tmpTable, caption.placement="top",
       sanitize.text.function= function(x){x})

which result in a .tex file like

......
\begin{table}[ht]
\begin{center}
\caption{Simulated data}
\label{tab:five}
\begin{tabular}{rrl}
   \hline
& Mean & Std.Dev \\
   \hline
   1 & 0.46 & $\pm$0.42 \\
   2 & 0.81 & $\pm$0.69 \\
   3 & 0.17 & $\pm$0.56 \\
   4 & 0.15 & $\pm$1.02 \\
   5 & 0.60 & $\pm$1.37 \\
   6 & 0.48 & $\pm$1.39 \\
    \hline
\end{tabular}
\end{center}
\end{table}\end{document}

so it seems that there's no need to tweak the sanitize.text.function

Thanks again.

-- 
Ottorino



More information about the R-help mailing list