Skip to content
Prev 246070 / 398513 Next

latex() etc.: How to nicely format a matrix for a LaTeX document?

Thanks, John, I did.

Here is an update [not all problems are solved; can they be?]:

Consider:

library(xtable)
mat <- matrix(c(1,NA,3,100,10012.23423,4), ncol = 3, byrow = TRUE)
print(xtable(mat, digits = 1), floating = FALSE, only.contents = TRUE, 
      include.rownames = FALSE, include.colnames = FALSE, hline.after = NULL)

With this one obtains a clean output of the rows (maybe someone knows how to suppress the "% latex table generated..." that is displayed). 
However, as you can see from the output, the "&" symbols are not vertically aligned (that would be quite helpful in reading the table in a source file). This is even worse if you have row names of different lengths... 

So my questions (2) and (3) are solved, but (1) remains. Is there any way to (maybe) first format the matrix entries to get the right alignment in xtable()?

Cheers,

Marius
On 2010-12-30, at 21:29 , John Kane wrote: