Dear R-Devel subscriber,
I encountered the following problem for tex-formatted table with
xtable(). Suppose I do want the following matrix as a table in LaTeX:
library(xtable)
a11 <- "\\color{green}\\textbf{big green}"
a21 <- "\\color{red}\\textbf{big red}"
a12 <- "\\color{green}green"
a22 <- "\\color{red}red"
A <- matrix(c(a11, a21, a12, a22), nrow = 2, ncol = 2)
colnames(A) <- c("big", "normal")
rownames(A) <- c("green", "red")
A
xtable(A, vsep=c('@{\\hspace{0.1cm}}', rep('@{\\hspace{0.4cm}}', 6), '@{\\hspace{0.1cm}}'))
I do get the following output:
% latex table generated in R 2.5.0 by xtable 1.4-3 package
% Fri Apr 27 13:19:43 2007
\begin{table}[ht]
\begin{center}
\begin{tabular}{rll}
\hline
& big & normal \\
\hline
green & $\backslash$color\{green\}$\backslash$textbf\{big green\} & $\backslash$color\{green\}green \\
red & $\backslash$color\{red\}$\backslash$textbf\{big red\} & $\backslash$color\{red\}red \\
\hline
\end{tabular}
\end{center}
\end{table}
Please, note that the curly braces are prefixed with a backslash and the
double backslashes are interpreted as math backslashes. The above code
snippet worked fine in R 2.4.1 and I reckon that this behaviour might be
due to:
o There is a warning if \ is used unnecessarily in a string when
being parsed, e.g. "\." where probably "\\." was intended.
("\." is valid, but the same as ".".) Thanks to Bill Dunlap
for the suggestion.