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.
Anyway, has somebody else encountered this problem and/or is so kind and give me
some hints/pointers to circumvent this problem?
Many thanks in advance,
Bernhard
> version
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 5.0
year 2007
month 04
day 23
svn rev 41293
language R
version.string R version 2.5.0 (2007-04-23)
Dr. Bernhard Pfaff
Global Structured Products Group
(Europe)
Senior Analyst
Invesco Asset Management Deutschland GmbH
Bleichstrasse 60-62
D-60313 Frankfurt am Main
Tel: +49(0)69 29807 230
Fax: +49(0)69 29807 178
Email: bernhard_pfaff at fra.invesco.com
Gesch?ftsf?hrer: Karl Georg Bayer, Bernhard Langer, Alexander Lehmann, Christian
Puschmann
Handelsregister: Frankfurt am Main, HRB 28469
Sitz der Gesellschaft: Frankfurt am Main
*****************************************************************
Confidentiality Note: The information contained in this mess...{{dropped}}
On Fri, 27 Apr 2007, Pfaff, Bernhard Dr. wrote:> 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.How can a warning that you are not showing (and I don't see when running your code) have anything to do with this? That change is just to add a warning: there is no change in the parsed code. I get the same behaviour in 2.4.1 with xtable 1.4-3. Have you perhaps updated 'xtable' as well as R and are blaming R for an 'xtable' change? As ?print.xtable says From version 1.4-3, all non-numeric columns are sanitized, and all LaTeX special characters are sanitised for LaTeX output. See the vignette for an example of customising the sanitization. [...] -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595