When I generate a LaTeX table using xtable I have been setting column names to strings with LaTeX code in order to get features like subscripts in the column headings. I recently had to reinstall xtable and discovered that all my LaTeX column headings were printing out in LaTeX code rather than with LaTeX formatting. For example, with the older xtable I could give my column a name something like "$A_b$" to get printed column heading of "A" with the subscript "b." Now my printed column heading is "$A_b$" and the LaTeX code in the .tex file generated by Sweave is "\$A\_b\$". It seems that the newest version of print.xtable takes all my LaTeX special characters and inserts backslashes, making LaTeX print the special characters rather than interpreting them. Is there a way to keep xtable from "fixing" my column names like this? Is there another (maybe better) way to get nicely LaTeX formatted column headings from xtable? Thanks, Ian
I would use latex() in the Hmsic package. Here is a short example
tmp <- matrix(1:12,4)
library(Hmisc)
tmp.latex <- latex(tmp,
colheads=c("abc$_1$","def$^{12}_4$","$g\\times
h$"))
## note the escaped "\" in the above colheads vector
print.default(tmp.latex)
Copy the contents of the file referenced in tmp.latex to your
real myfile.tex file.
There are about a zillion optional arguments to latex() that give you very fine
control over the appearance of the typeset object. See ?latex