I'm trying to get R to print a matrix as a LaTeX matrix using xtable
, using the LaTeX environment bmatrix
.
a <- matrix(rnorm(25), 5 ,5)
x <- xtable(x)
> print(x, floating=FALSE, tabular.environment="bmatrix", hline.after=NULL, include.rownames=FALSE, include.colnames=FALSE)
I get this:
% latex table generated in R 2.14.1 by xtable 1.6-0 package
% Fri May 11 08:16:12 2012
\begin{bmatrix}{rrrrr}
0.70 & 1.30 & -0.44 & 0.97 & -0.86 \\
-1.23 & -0.59 & 0.04 & -0.32 & 0.12 \\
-0.64 & -0.19 & 0.11 & 0.77 & 0.05 \\
0.56 & -0.28 & -2.05 & 1.01 & -1.77 \\
0.02 & -1.24 & 0.51 & -0.49 & 1.23 \\
\end{bmatrix}
Is there a way to suppress the {rrrrr}
alignment attribute, or otherwise get xtable to produce a bracketed matrix that I can use in a math environment?
Best Answer
Use
align
argument ofxtable
, setting alignment string to empty. This produces an empty group after\begin{bmatrix}
, which is harmless: