7

I am still a newbie in LaTeX and I am trying to write something like that but I couldn't find how to do so.

enter image description here

Is there an efficient way to write this and if I have multiple steps to show in the reduction how do I align them?

Thanks!

Marian G.
  • 1,951
  • 1
  • 9
  • 14
Moh18
  • 101
  • 1
    Welcome to TeX.SE. Please do tell us what you've tried so far and where you feel you're getting stuck. – Mico Oct 13 '19 at 17:03
  • Minor nit: I’m more used to seeing columns of numbers align right than left or center. Sebastiano’s answer already matches the output you want, so +1. – Davislor Oct 14 '19 at 21:49

2 Answers2

8

I would use something like this:

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
  \left(
  \begin{array}{*4{l}|l}
    1 & 1 & 1 & 1 & b_1\\
    0 & 2 & 3 & 3 & b_2-b_1\\
    0 & 2 & 3 & 3 & b_3-b_1\\
    0 & 4 & 4 & 5 & b_4-b_1\\
  \end{array}
  \right)
  \xrightarrow[L_4 \rightarrow L_4-2L_2]{L_3 \rightarrow L_3-L_2}
  \left(
  \begin{array}{*4{l}|l}
    1 & 1 & 1 & 1 & b_1\\
    0 & 2 & 3 & 3 & b_2-b_1\\
    0 & 0 & 0 & 0 & b_3-b_1-b_2\\
    0 & 0 & -2 & -1 & b_4+b_1-2b_2\\
  \end{array}
  \right).
\]
\end{document}

enter image description here

Franck Pastor
  • 18,756
  • Since you're using array, you might consider aligning the first four columns as 4r instead of 4l so that the minus signs don't shove the negative values out of line. – barbara beeton Oct 13 '19 at 17:40
  • Thanks! However, I have another question. I am trying to write this [\left(\begin{pmatrix} 1 \ 0 \ 0 \ 0 \end{pmatrix},\begin{pmatrix} 0 \ \frac{1}{4} \ \frac{1}{2} \ 0 \end{pmatrix},\begin{pmatrix} 1 \ \frac{1}{4} \ -\frac{1}{2} \ 0 \end{pmatrix},\begin{pmatrix} 0 \ -\frac{1}{2\sqrt{2}} \ \frac{1}{\sqrt{2}} \ \frac{1}{\sqrt{2}} \ 0\end{pmatrix}\right)] but is there a way to align number with \begin{pmatrix} and the fractions are a little too close of each others (I don't know how to space them) – Moh18 Oct 13 '19 at 18:12
  • @barbarabeeton this is what I would have done for myself, but I wanted to reproduce what Moh18 wanted. – Franck Pastor Oct 13 '19 at 18:41
  • @Moh18 I suggest opening another subject to address this new problem :-) – Franck Pastor Oct 13 '19 at 18:42
  • @FranckPastor https://tex.stackexchange.com/questions/512111/aligning-and-spaces-for-negative-numbers-and-fractions-in-a-matrix – Moh18 Oct 13 '19 at 19:08
  • @FranckPastor If, between the two matrices, I have to show more that two steps. For example, $L_4 \rightarrow L_4-2L_2$ ,$L_3 \rightarrow L_3-L_2$,$L_2 \rightarrow \frac{1}{2}$. How can I write them under or over the $\xrightarrow$? – Moh18 Oct 14 '19 at 03:54
  • @barbarabeeton If, between the two matrices, I have to show more that two steps. For example, $L_4 \rightarrow L_4-2L_2$ ,$L_3 \rightarrow L_3-L_2$,$L_2 \rightarrow \frac{1}{2}$. How can I write them under or over the $\xrightarrow$? – Moh18 Oct 14 '19 at 03:54
  • @Moh18 -- For expressions over/under xrightarrow, look at the instructions and examples in section 4.9, "Extensible arrows", in the amsmath user guide (texdoc amsldoc). Also, the answers here do show the proper input method. – barbara beeton Oct 14 '19 at 15:58
8

EDIT: 2020-7-18 Another option could be using the nicematrix package (see the recent version and the comment of the author of the package). Here there is my approach:

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{nicematrix}
\usepackage{mathtools}
\begin{document}
\[\left(\begin{NiceArray}{cccc|l}
1 & 1 & 1 & 1 & b_1\\
0 & 2 & 3 & 3 & b_2-b_1\\
0 & 2 & 3 & 3 & b_3-b_1\\
0 & 4 & 4 & 5 & b_4-b_1
\end{NiceArray}\right)
\xrightarrow[L_4 \rightarrow L_4-2L_2]{L_3 \rightarrow L_3-L_2}
\left(\begin{NiceArray}{cccc|l}
1 & 1 & 1 & 1 & b_1\\
0 & 2 & 3 & 3 & b_2-b_1\\
0 & 0 & 0 & 0 & b_3-b_1-b_2\\
0 & 0 & -2 & -1 & b_4+b_1-2b_2\\
\end{NiceArray}\right).\]
\end{document}

ADDENDUM by comment of the user

There are several procedures to have, for example, on the same arrow your reductions: see this link how to force text to write in two or more lines in overset command for example.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{nicematrix}
\usepackage{mathtools}
\begin{document}
\[\left(\begin{NiceArray}{cccc|l}
1 & 1 & 1 & 1 & b_1\\
0 & 2 & 3 & 3 & b_2-b_1\\
0 & 2 & 3 & 3 & b_3-b_1\\
0 & 4 & 4 & 5 & b_4-b_1
\end{NiceArray}\right)
\xrightarrow{
            \begin{subarray}{l}
                L_4 \rightarrow L_4-2L_2\\
                L_3 \rightarrow L_3-L_2\\
                L_2 \rightarrow \frac{1}{2}
                %%% here you can add other steps
            \end{subarray}
        }
\left(\begin{NiceArray}{cccc|l}
1 & 1 & 1 & 1 & b_1\\
0 & 2 & 3 & 3 & b_2-b_1\\
0 & 0 & 0 & 0 & b_3-b_1-b_2\\
0 & 0 & -2 & -1 & b_4+b_1-2b_2\\
\end{NiceArray}\right).\]
\end{document}

You, if it is possible, read the guide of nicematrix package you could get a better result (see the image of the guide to pag. 18, for example).

enter image description here

Sebastiano
  • 54,118
  • 1
    Thank you for you response! – Moh18 Oct 13 '19 at 19:15
  • @Moh18 I'm happy when I help someone. Glad I helped you. – Sebastiano Oct 13 '19 at 19:16
  • If, between the two matrices, I have to show more that two steps. For example, $L_4 \rightarrow L_4-2L_2$ ,$L_3 \rightarrow L_3-L_2$,$L_2 \rightarrow \frac{1}{2}$. How can I write them under or over the $\xrightarrow$? – Moh18 Oct 14 '19 at 03:52
  • @Moh18 Hi, I have done an addendum for your request. My best regards, – Sebastiano Oct 14 '19 at 20:58
  • 1
    In this answer, since version 5.0 of nicematrix one must write cccc|l instead of CCCC|L in the preambles of {NiceArray} (but there is an option for backward compatibility). – F. Pantigny Jul 18 '20 at 21:15
  • @F.Pantigny I'll correct that immediately and thank you immensely. – Sebastiano Jul 18 '20 at 21:17