Typography with TeX and LaTeX

## An extension to amsmath matrix environments

September 30th, 2008 by Stefan Kottwitz

Inspired by a question on matheplanet.com and remembering the cases redefinition I’ve shown some days ago I got the idea to extend the internal macro \env@matrix of amsmath.sty. I wanted to use the matrix environments together with array features like alignment, vertical lines, formatting and special commands.
The mathtools package provides something similar by its starred matrix environments that support one optional parameter that will be applied to all matrix columns. The following redefinition will introduce an optional parameter to amsmath array environments that allows column-specific customization:

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

If you put these lines into your document preamble the pmatrix, bmatrix, vmatrix, Bmatrix, Vmatrix etc. environments will accept an optional parameter. If you don’t provide this parameter those environments will work like usual. Here’s one example showing an augmented matrix containing a vertical line:

$\begin{pmatrix}[cc|c] 1 & 2 & 3\\ 4 & 5 & 9 \end{pmatrix}$

Another more complex example just showing some array features like different alignment because of the signs, color change and bold font:

$\begin{bmatrix}[*2cr@{\quad}|@{\quad}>{\bf\color{red}}r] a & b & 1 & 4 \\ c & d & -2 & -3 \end{bmatrix}$

Though \bf is an obsolete font command standard classes still support it and I’ve just used it because \boldmath is invalid in math mode, in general I advice against using \bf.

This entry was posted on Dienstag, September 30th, 2008 at 22:41 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.

### 5 responses about “An extension to amsmath matrix environments”

1. Graham Cranston said:

2. Stephen Siklos said:

That’s brilliant - thanks for posting it.

3. Daniel Moser said:

Very, very useful! Thanks!

4. Acharya said:

Great stuff. Very useful.

5. John Roumeliotis said:

Good stuff. You can also use the package arydshln if you want to add dashed lines in an array environment