32

I'm trying to reproduce the following calculation of a determinant in LaTeX:

example image

Any ideas? I thought of using the tabular environment but unfortunately I'm not able to align the "=" correctly.

1
  • 3
    Please, add a Minimal Working Example, so the people could easily think and try with your problem.
    – Manuel
    Commented Jan 11, 2013 at 20:01

4 Answers 4

28

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

15
  • 6
    Please, don't recommend eqnarray under any circumstances.
    – egreg
    Commented Jan 11, 2013 at 20:26
  • 3
    Very nice except the eqnarray. Here is one out of many reasons. (vote capped for today)
    – percusse
    Commented Jan 11, 2013 at 20:29
  • 1
    s/eqnarray/align/g and s/&=&/&=/g should do the trick
    – cmhughes
    Commented Jan 11, 2013 at 20:35
  • 1
    Very nice done. Thank you @Américo Tavares for your help. 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?
    – Martin
    Commented Jan 11, 2013 at 20:39
  • 2
    @AméricoTavares To right align the columns you could use \begin{vmatrix*}[r] … \end{vmatrix*}.
    – Manuel
    Commented Jan 11, 2013 at 21:29
13

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

5
  • And if that's always the notation, you could add ) to the environment so you don't need to write it all the times. Apart from that, I don't find this notation pleasant (*), etc. on the left of the matrix), I don't suggest any other, but I think this is not beautiful.
    – Manuel
    Commented Jan 11, 2013 at 21:27
  • @Manuel I thought about adding the ) to the definition, but maybe leaving it in the cell makes clearer what the number is for. I don't like the notation, either. There's no need to use the Laplace development at any stage, the usual Gaussian elimination suffices.
    – egreg
    Commented Jan 11, 2013 at 21:30
  • 1
    Nitpicking: In the OP's picture, the numbers are right aligned.
    – mafp
    Commented Jan 12, 2013 at 1:23
  • 1
    @mafp I never right align the coefficients of a matrix. Adding that feature is possible, though.
    – egreg
    Commented Jan 12, 2013 at 10:45
  • @egreg Oh, I would not write the whole determinant computation that way. But it is what the OP asked for. It works with mathtools, and then vmatrix[r], right?
    – mafp
    Commented Jan 12, 2013 at 13:12
9

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.

1

Here's another style I made. If you aren't doing determinants, replace the "vmatrix" with "bmatrix". I don't know how to post a picture of what it looks like.

enter image description here

\paragraph{Example}
Evaluate the determinant
\begin{align*}
  \begin{vmatrix*}[r]
        1 & -12 & 5 & -3 \\
        2 & -21 & 22 & -7 \\
        2 & -9 & 41 & -10 \\
        0 & 3 & 7 & 3
    \end{vmatrix*}.
\end{align*}

\paragraph{Solution}
\begin{align*}
  \begin{vmatrix*}[r]
        1 & -12 & 5 & -3 \\
        2 & -21 & 22 & -7 \\
        2 & -9 & 41 & -10 \\
        0 & 3 & 7 & 3
    \end{vmatrix*}
    &=
  \begin{vmatrix*}[r]
        1 & -12 &  5 & -3 \\
        0 &   3 & 12 & -1 \\
        0 &  15 & 31 & -4 \\
        0 &   3 &  7 &  3
    \end{vmatrix*}
    \quad
    \begin{matrix*}[l]
        \\ 
        \leftarrow -2r_1+r_2 \ \text{\scriptsize (no change in determinant)} \\
        \leftarrow  -2r_2+r_3 \ \text{\scriptsize (no change in determinant)} \\
        \\
    \end{matrix*} \\
    &=
  -\begin{vmatrix*}[r]
        1 & -3 &  5 & -12 \\
        0 & -1 & 12 &   3 \\
        0 & -4 & 31 &  15 \\
        0 &  3 &  7 &   3
    \end{vmatrix*}
    \quad
    \begin{matrix*}[l]
        \\ 
        \leftarrow c_2 \leftrightarrow c_4 \ \text{\scriptsize (negate determinant)} \\
        \\
        \\
    \end{matrix*} \\
    &=
  -\begin{vmatrix*}[r]
        1 & -3 &   5 & -12 \\
        0 &  1 & -12 &  -3 \\
        0 &  4 & -31 & -15 \\
        0 &  3 &   7 &   3
    \end{vmatrix*}
    \quad
    \begin{matrix*}[l]
        \\ 
        \leftarrow -r_2 \ \text{\scriptsize (negate determinant)} \\
        \leftarrow -r_3 \ \text{\scriptsize (negate determinant)} \\
        \\
    \end{matrix*} \\
    &=
  -\begin{vmatrix*}[r]
        1 & -3 &   5 & -12 \\
        0 &  1 & -12 &  -3 \\
        0 &  0 &  17 &  -3 \\
        0 &  0 &  43 &  12
    \end{vmatrix*}
    \quad
    \begin{matrix*}[l]
        \\ 
        \\ 
        \leftarrow -4r_2+r_3 \ \text{\scriptsize (no change in determinant)} \\
        \leftarrow -3r_2+r_4 \ \text{\scriptsize (no change in determinant)}
    \end{matrix*} \\
    &=
  -17\begin{vmatrix*}[r]
        1 & -3 &   5 & -12 \\
        0 &  1 & -12 &  -3 \\
        0 &  0 &   1 &  -\nicefrac{3}{17} \\
        0 &  0 &  43 &  12
    \end{vmatrix*}
    \quad
    \begin{matrix*}[l]
        \\ 
        \\ 
        \leftarrow \nicefrac{1}{17}r_3 \ \text{\scriptsize (factor out 17)} \\
        \\
    \end{matrix*} \\
    &=
  -17\begin{vmatrix*}[r]
        1 & -3 &   5 & -12 \\
        0 &  1 & -12 &  -3 \\
        0 &  0 &   1 &  -\nicefrac{3}{17} \\
        0 &  0 &  0 &  \nicefrac{333}{17}
    \end{vmatrix*}
    \quad
    \begin{matrix*}[l]
        \\ 
        \\ 
        \\ 
        \leftarrow -43r_3+r_4 \ \text{\scriptsize (no change in determinant)}
    \end{matrix*} \\
    &= -17\left(\frac{333}{17}\right) = \bm{-333}.
\end{align*}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .