I know that this is an old question, but to whoever stumbles upon this from a Google search (like I just did) another very elegant solution for this is using the starred matrix environments of mathtools
:
\begin{matrix*} [〈col〉] 〈contents〉 \end{matrix*}
: simple matrix,
\begin{pmatrix*}[〈col〉] 〈contents〉 \end{pmatrix*}
: matrix surrounded by matching parenthesis,
\begin{bmatrix*}[〈col〉] 〈contents〉 \end{bmatrix*}
: matrix surrounded by matching square brackets,
\begin{Bmatrix*}[〈col〉] 〈contents〉 \end{Bmatrix*}
: matrix surrounded by matching curly brackets (braces),
\begin{vmatrix*}[〈col〉] 〈contents〉 \end{vmatrix*}
: matrix surrounded by matching vertical lines (like for determinant),
\begin{Vmatrix*}[〈col〉] 〈contents〉 \end{Vmatrix*}
: matrix surrounded by matching double vertical lines.
The <col>
optional argument specifies the column alignment, and should be c
, l
or r
for centered (default), left-aligned and right-aligned, respectively. Consider the following example,
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
\begin{pmatrix*}[r]
-1 & 3 \\
2 & -4
\end{pmatrix*}
\]
\[
\begin{Bmatrix*}[l]
1.001 &\hdots & 3 \\
2.3 & \hdots & 4.2
\end{Bmatrix*}
\]
\[
\begin{Vmatrix*}[c]
1 & 3 \\
\tfrac{1}{2} & 4.2
\end{Vmatrix*}
\]
\end{document}
which yields
The mathtools
package is an extension of amsmath
that fixes various bugs/deficiencies and adds some useful tools (like the starred matrix environments).