# raggedleft (right-aligned) entries in pmatrix? [duplicate]

I'm using pmatrix from amsmath package and would like the output to align all entries in the same column to be align on the right hand side, as shown here in the code:

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


by default, pmatrix will center.

Any way to do this?

-
from the amsmath users guide: "(If you need left or right alignment in a column or other special formats you must resort to array.)" (p.8) –  barbara beeton Feb 13 at 14:20

## marked as duplicate by tohecz, Svend Tveskæg, Peter Jansson, Werner, cmhughesFeb 13 at 16:11

You can use the pmatrix* environment of the mathtools package:

\documentclass{article}
\usepackage{mathtools} % loads amsmath and some very useful complements
\begin{document}
$\begin{pmatrix*}[r] -1 & 1 & -2\\ 0 & -1 & 4\\ 0 & 0 & 1 \end{pmatrix*}$
\end{document}


-

The new tabstackengine package can also do this, including different column alignments, as in the 2nd example. One bug I need to still resolve in the package is that - characters are taken as binary minus signs, rather than unary negative signs. The workaround is to enclose them in braces, as I did here.

\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\begin{document}
$\setstacktabbedgap{1ex}\parenMatrixstack[r]{% {-}1 & 1 & {-}2\\ 0 & {-}1 & 4\\ 0 & 0 & 1 }$
$\left(\tabularCenterstack{lcr}{% {-}1 & 1 & {-}2\\ 0 & {-}1 & 4\\ 0 & 0 & 1 }\right)$
\end{document}


-