[Rd] Problem with formatted xtable in R 2.5.0

Pfaff, Bernhard Dr. Bernhard_Pfaff at fra.invesco.com
Fri Apr 27 13:24:30 CEST 2007

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:

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")
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
 & big & normal \\
green & $\backslash$color\{green\}$\backslash$textbf\{big green\} & $\backslash$color\{green\}green \\
  red & $\backslash$color\{red\}$\backslash$textbf\{big red\} & $\backslash$color\{red\}red \\

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,

> version
platform       i386-pc-mingw32             
arch           i386                        
os             mingw32                     
system         i386, mingw32               
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
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}}

More information about the R-devel mailing list