How to draw the calculation of a determinant?

I just have one question: The numbers in the determine itself are all right aligned. You can see it in column 3, row 1 and 2 in the picture I posted. The 2 is just above the -2 and they are both right aligned, no matter if there is a minus or not. Do you have any idea how to realize that? -- user24295

No, I don't, but according to comments by percusse and Manuel you can do that by loading mathtools instead of amsmath and use \begin{vmatrix*}[r] … \end{vmatrix*}. I haven't checked though by myself. But I do recomment keep the standard alignement provided by \begin{vmatrix} ... \end{vmatrix}.


UPDATE with align. Thanks to cmhughes's advice I've replaced eqnarray with alignand &=& with &=. ADDED. As commented by egreg eqnarray should be avoided (see e.g. here and here) due to spacing discrepancies.

The updated code is:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align}
\det A &=\left. 
\begin{array}{c}
\;\;\text{*)} \\ 
-1\text{)} \\ 
-2\text{)} \\ 
-2\text{)}
\end{array}
\right. 
\begin{vmatrix}
1 & 3 & 2 & -6 \\ 
1 & 2 & -2 & -5 \\ 
2 & 4 & -2 & -9 \\ 
2 & 4 & -6 & -9  \notag
\end{vmatrix}
=
\begin{vmatrix}
1 & 3 & 2 & -6 \\ 
0 & -1 & -4 & 1 \\ 
0 & -2 & -6 & 3 \\ 
0 & -2 & -10 & 3
\end{vmatrix}
\\ \notag
&& \\ 
&=\left. 
\begin{array}{c}
\;\;\text{*)} \\ 
-2\text{)} \\ 
-2\text{)}
\end{array}
\right. 
\begin{vmatrix}
1 & 4 & 1 \\ 
2 & 6 & 3 \\ 
2 & 10 & 3
\end{vmatrix}
=
\begin{vmatrix}
1 & 4 & 1 \\ 
0 & -2 & 1 \\ 
0 & 2 & 1
\end{vmatrix}
=
\begin{vmatrix}
-2 & 1 \\ 
2 & 1
\end{vmatrix}
=-4\notag
\end{align}

\end{document} 

The Output is:

enter image description here


We can use the following code (with eqnarray)

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{eqnarray*}
\det A\; &=&\left. 
\begin{array}{c}
\;\;\text{*)} \\ 
-1\text{)} \\ 
-2\text{)} \\ 
-2\text{)}
\end{array}
\right. 
\begin{vmatrix}
1 & 3 & 2 & -6 \\ 
1 & 2 & -2 & -5 \\ 
2 & 4 & -2 & -9 \\ 
2 & 4 & -6 & -9
\end{vmatrix}
=
\begin{vmatrix}
1 & 3 & 2 & -6 \\ 
0 & -1 & -4 & 1 \\ 
0 & -2 & -6 & 3 \\ 
0 & -2 & -10 & 3
\end{vmatrix}
\\
&& \\
&=&\left. 
\begin{array}{c}
\;\;\text{*)} \\ 
-2\text{)} \\ 
-2\text{)}
\end{array}
\right. 
\begin{vmatrix}
1 & 4 & 1 \\ 
2 & 6 & 3 \\ 
2 & 10 & 3
\end{vmatrix}
=
\begin{vmatrix}
1 & 4 & 1 \\ 
0 & -2 & 1 \\ 
0 & 2 & 1
\end{vmatrix}
=
\begin{vmatrix}
-2 & 1 \\ 
2 & 1
\end{vmatrix}
=-4
\end{eqnarray*}

\end{document}

to type

enter image description here


You can define an xvmatrix environment for the "eXtended" matrix, where you specify the coefficients as a first column:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newenvironment{xvmatrix}% eXtended vmatrix
  {\left.\array{@{}r |@{\,}*\c@MaxMatrixCols c}}
  {\endarray\kern-\arraycolsep\right|}
\makeatother

\begin{document}

\begin{align*}
\det A &=
\begin{xvmatrix}
 *) & 1 & 3 &  2 & -6 \\ 
-1) & 1 & 2 & -2 & -5 \\ 
-2) & 2 & 4 & -2 & -9 \\ 
-2) & 2 & 4 & -6 & -9
\end{xvmatrix}
=
\begin{vmatrix}
1 & 3 & 2 & -6 \\ 
0 & -1 & -4 & 1 \\ 
0 & -2 & -6 & 3 \\ 
0 & -2 & -10 & 3
\end{vmatrix}
\\
&=
\begin{xvmatrix}
 *) & 1 &  4 & 1 \\ 
-2) & 2 &  6 & 3 \\ 
-2) & 2 & 10 & 3
\end{xvmatrix}
=
\begin{vmatrix}
1 & 4 & 1 \\ 
0 & -2 & 1 \\ 
0 & 2 & 1
\end{vmatrix}
=
\begin{vmatrix}
-2 & 1 \\ 
2 & 1
\end{vmatrix}
=-4
\end{align*}

\end{document}

enter image description here

Update 2020

You can use the nicematrix package.

\documentclass{article}
\usepackage{amsmath,nicematrix}

\begin{document}

\begin{align*}
\det A &=
\begin{vNiceMatrix}[first-col]
 *) & 1 & 3 &  2 & -6 \\ 
-1) & 1 & 2 & -2 & -5 \\ 
-2) & 2 & 4 & -2 & -9 \\ 
-2) & 2 & 4 & -6 & -9
\end{vNiceMatrix}
=
\begin{vmatrix}
1 & 3 & 2 & -6 \\ 
0 & -1 & -4 & 1 \\ 
0 & -2 & -6 & 3 \\ 
0 & -2 & -10 & 3
\end{vmatrix}
\\
&=
\begin{vNiceMatrix}[first-col]
 *) & 1 &  4 & 1 \\ 
-2) & 2 &  6 & 3 \\ 
-2) & 2 & 10 & 3
\end{vNiceMatrix}
=
\begin{vmatrix}
1 & 4 & 1 \\ 
0 & -2 & 1 \\ 
0 & 2 & 1
\end{vmatrix}
=
\begin{vmatrix}
-2 & 1 \\ 
2 & 1
\end{vmatrix}
=-4
\end{align*}

\end{document}

enter image description here


I do not consider a good habit introducing such a notation, my experience is that it only confuses people. Mathematical formalism is there for a reason. You can try the following:

enter image description here

\documentclass{article}
\pagestyle{empty}
\usepackage{amsmath}
\begin{document}

\begin{align*}
  \det A&=
  \underbrace{\begin{vmatrix}
    1 & 0 & 0 & 0 \\ 
    -1 & 1 & 0 & 0 \\ 
    -2 & 0 & 1 & 0 \\ 
    -2 & 0 & 0 & 1
  \end{vmatrix}}_{=1}
  \cdot
  \begin{vmatrix}
    1 & 3 & 2 & -6 \\ 
    1 & 2 & -2 & -5 \\ 
    2 & 4 & -2 & -9 \\ 
    2 & 4 & -6 & -9
  \end{vmatrix}
  =
  \begin{vmatrix}
    1 & 3 & 2 & -6 \\ 
    0 & -1 & -4 & 1 \\ 
    0 & -2 & -6 & 3 \\ 
    0 & -2 & -10 & 3
  \end{vmatrix}
  \\
  &=
  \underbrace{\begin{vmatrix}
    1 & 0 & 0 \\ 
    -2 & 1 & 0 \\ 
    -2 & 0 & 1
  \end{vmatrix}}_{=1}
  \cdot
  \begin{vmatrix}
    1 & 4 & 1 \\ 
    2 & 6 & 3 \\ 
    2 & 10 & 3
  \end{vmatrix}
  =
  \begin{vmatrix}
    1 & 4 & 1 \\ 
    0 & -2 & 1 \\ 
    0 & 2 & 1
  \end{vmatrix}
  =
  \begin{vmatrix}
    -2 & 1 \\ 
    2 & 1
  \end{vmatrix}
  =-4
\end{align*}

\end{document}

Somehow, it would make more sense if you tried to demonstrate the column manipulation, because then the triangle unit-determinant matrix would come on the right side. But even this is completely clear IMHO.