Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
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

2 Answers 2

up vote 5 down vote accepted

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}

enter image description here

share|improve this answer

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}

enter image description here

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.