[texhax] Matrix aligment

Philip G. Ratcliffe philip.ratcliffe at uninsubria.it
Thu Mar 29 10:47:15 CEST 2007

> I would like to make a matrix like this
> -1  1  1
> 1  1  1
> But the problem I like is to align to the right, because the 
> sign with 
> the number are always centered.
> Im using:
> \usepackage{amsmath}
> \begin{gather}
>    \begin{matrix}
>       -1&1&1
>        1&1&1
>    \end{matrix}
> \end{gather}

This is something of a failing on the part of amsmath - I can suggest three
possible solutions:

1. \newcommand\M{\hphantom{-}} 
Then insert \M wherevere necessary to adjust alignment 
(This is a useful general trick in arrays - I also use
\newcommand\Z{\hphantom{0}}, which works because all digits have the same

2. Use the array environment - which matrix is of course supposed to replace
- but then you'll have different interline and intercolumn spacing with
respect to any others using  matrix environment.

3. Hack amsmath's matrix, my preferred solution ;-), thus

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

This should either be loaded as part of a style file or placed between a
\makeatletter \makeatother pair in your preamble.  It defines an optional
argument to all the amsmath matrix environments, thus allowing 

\begin{..matrix}[r] ... \end{..matrix} 

The default is "c", following the original definition, and you can obviously
put l, c, or r.

Cheers,  Phil

P.S.  When I have time I may suggest this modification to the amsmath

More information about the texhax mailing list