Typography with TeX and LaTeX

## Matrices with alignment

Mai 5th, 2008 by Stefan Kottwitz

The entries of matrix columns are centered by default. Let’s see an example:

$\begin{pmatrix} 1 & 2 & 1 \\ 0 & -2 & -3 \\ 0 & 3 & -2 \end{pmatrix}$

Output:

For right alignment you could use an array environment instead of pmatrix. I will show a possibility to get left, right or centered alignment by redefining the internal amsmath macro \env@matrix. Its original definition in version 2.13 is:

\def\env@matrix{\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{*\c@MaxMatrixCols c}}

I introduce an optional parameter, its default value is c:

\makeatletter
\renewcommand*\env@matrix[1][c]{\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{*\c@MaxMatrixCols #1}}
\makeatother

Now, if you write \begin{pmatrix}[r] … above you will get:

This topic was discussed in the Matheplanet Forum.

This entry was posted on Montag, Mai 5th, 2008 at 15:30 and is filed under Mathematics. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

### 2 responses about “Matrices with alignment”

1. Neil said:

Thanks for this — I wish that it were in amslatex already!

2. sixdegree said:

You can also use the pmatrix* environment provided by the mathtools package like this:
\begin{pmatrix*}[r]…