An extension to amsmath matrix environments
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.
Comments (9)