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

This question already has an answer here:

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?

-

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

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 '14 at 14:20

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. EDITED to reflect updated package (bug workaround no longer needed).

\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}


-