0

During preparing a note about elementary row operations, I did the following as similar as I had found through the site:

\documentclass[a4paper,12pt]{book}‎
\usepackage{amsmath,amssymb,amsthm,amsfonts}‎ 
\begin{document}‎‎
‎‎\begin{pmatrix}
‎2‎‎ & 1 \\ 
1 & -5\\‎
3 & \circled{7} 
\end{pmatrix}‎
‎‎\xrightarrow ‎{‎\tfrac{-12}{2}‎R_1+ R_3‎\mapsto ‎R_3}‎‎
\begin{pmatrix}
‎2‎‎ & 1 \\ 
1 & -5\\‎
-21 & \circled{5-‎}‎ 
\end{pmatrix}
‎\end{document}‎

‎ Is it possible to do it as the picture?

enter image description here

I think, If I can do that, they will be illustrated nicely.

Mikasa
  • 589
  • Hi. Please a compilable MWE. You have been on this network for more than 4 years, you must know what a MWE is. –  Dec 03 '18 at 06:30
  • Which package do you use for the \circled command? –  Dec 03 '18 at 06:47
  • @DũngVũ I see you deleted your answer, but you can undelete it, saying "to simplify CarLaTeX's answer, you could use an array instead of a tabular." I rejected your edit to my question because I already edited it meanwhile. – CarLaTeX Dec 03 '18 at 09:33
  • @CarLaTeX Oh yeah, that's right. However, your answer is much better than mine, so I decided to do so, in addition with upvote your answer. Even I got help from you in your answer! As for the edit, everyone sees the mistake in the link, so I know you will edit it. However, in case you left TeX.SX right after you posted this question and forgot to edit your answer (sometimes I do so :)) I just want to complete your answer :)) –  Dec 03 '18 at 09:52
  • @DũngVũ: Thanks for evey second my friend! I wish I had you answer here before I lost that. May I ask you to undelete it again. It would be kind of you. Thanks. – Mikasa Dec 04 '18 at 03:08
  • @mrs In that case, my friend, I have already undeleted it :)) –  Dec 04 '18 at 04:12

3 Answers3

7

Since you didn't provide a complete MWE, I used a \circled command found here.

By the way, the parts already written in your MWE don't exactly correspond to the image, I've replicated the image.

Edit: modified to remedy the Command \scriptsize invalid in math mode warning pointed out by egreg.

\documentclass[a4paper,12pt]{book}
\usepackage{amsmath,amssymb,amsthm,amsfonts}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(A.base)]{\node[circle,draw,inner 
sep=1](A){$#1$};}}% code from: https://tex.stackexchange.com/a/304891/101651
\usepackage{array}
\newcolumntype{R}{>{$\scriptstyle}r<{$}}
\usepackage{booktabs}
\begin{document}
    \[
    \begin{pmatrix}
    2 & 1 \\ 
    1 & -5\\
    3 & \circled{7} 
    \end{pmatrix}
    \xrightarrow[{ 
    \renewcommand*{\arraystretch}{0.8}\begin{tabular}{R@{$\scriptstyle 
    :\;\;$}R@{\hspace{4pt}}R}
        -12R_{1}  &  -24 & -12\\
        R_{3} & 3 & 7\\
        \cmidrule(r){2-3}
        \text{(new) } R_{3} & -21 & -5
        \end{tabular}}]{-12R_1+ R_3\mapsto R_3}
    \begin{pmatrix}
    2 & 1 \\ 
    1 & -5\\
    -21 & \circled{-5} 
    \end{pmatrix}
    \]
\end{document}

enter image description here

CarLaTeX
  • 62,716
  • Thanks for every second! That I didn't attach the requisite link and codes was due to the way I ask the question. I was not at home to give you whole 40 packages which I had called before the main codes. I apologize you and all who read this question. Thanks and regards again. – Mikasa Dec 04 '18 at 03:12
  • Yes. It is what I was looking for. Regards. – Mikasa Dec 04 '18 at 03:16
  • Command \scriptsize invalid in math mode – egreg Dec 04 '18 at 09:47
  • @egreg Overleaf strikes back: https://v2.overleaf.com/project/5bfa6d1b8dbef14ea3d0e63b (click on "show logs") – CarLaTeX Dec 04 '18 at 09:52
  • typo in last row, -21 should replace -2 –  Dec 04 '18 at 10:57
  • I can not correct the point raised by egreg because that would be plagiarizing his answer... –  Dec 04 '18 at 11:02
  • enjoy your upvotes so far, now he is going to steal the show :) –  Dec 04 '18 at 11:05
  • @jfbu lol but I'm not David, it's not the same thing :) – CarLaTeX Dec 04 '18 at 11:06
4

You want a properly defined array using \scriptstyle. The explain environment takes as argument the number of columns after the colon.

\documentclass[a4paper,12pt]{book}
\usepackage{amsmath,amssymb,amsthm,amsfonts}
\usepackage{tikz}
\usepackage{array}
\usepackage{booktabs}

\newcolumntype{R}{>{\scriptstyle}r}

% code from: https://tex.stackexchange.com/a/304891/101651
\newcommand*\circled[1]{%
  \tikz[baseline=(A.base)]{\node[circle,draw,inner sep=1](A){$#1$};}%
}
\newenvironment{explain}[1]
 {%
  \renewcommand{\arraystretch}{0.7}%
  \setlength{\aboverulesep}{0.5\aboverulesep}%
  \setlength{\belowrulesep}{0.5\belowrulesep}%
  \begin{array}{@{} R @{\scriptstyle\;:\;} *{#1}{R} @{}}
 }
 {\end{array}}

\begin{document}

\[
\begin{pmatrix}
2 & 1 \\ 
1 & -5\\
3 & \circled{7} 
\end{pmatrix}
\xrightarrow[
  \begin{explain}{2}
    -12R_{1} & -24 & -12\\
       R_{3} &   3 &   7\\
     \cmidrule(l){2-3}
     \text{(new) } R_{3} & -21 & -5
  \end{explain}
]{-12R_1+ R_3 \to R_3}
\begin{pmatrix}
2 & 1 \\ 
1 & -5\\
-21 & \circled{-5} 
\end{pmatrix}
\]

\end{document}

enter image description here

An alternative definition for explain is

\usepackage{environ}

\NewEnviron{explain}[1]
 {%
  \mbox{%
    \scriptsize
    \setlength{\aboverulesep}{0.5\aboverulesep}%
    \setlength{\belowrulesep}{0.5\belowrulesep}%
    $\begin{array}{@{} r @{\;:\;} *{#1}{r} @{}}
    \BODY
    \end{array}$%
  }%
}

Without environ it could be

\newenvironment{explain}[1]
 {%
  \hbox\bgroup
    \scriptsize
    \setlength{\aboverulesep}{0.5\aboverulesep}%
    \setlength{\belowrulesep}{0.5\belowrulesep}%
    $\begin{array}{@{} r @{\;:\;} *{#1}{r} @{}}%
  }
  {\end{array}$\egroup}
egreg
  • 1,121,712
1

@CarLaTeX's answer is very good! However, as an alternative solution, you can also use an array for the "table" below the arrow:

\documentclass[a4paper,12pt]{book}
\usepackage{amsmath,amssymb,amsthm,amsfonts}
\usepackage{array}
\begin{document}
\[
\left(\begin{array}{cc}
    2 & 1\\
    1 & -5\\
    3 & 7
\end{array}\right)\xrightarrow[
    \begin{scriptsize}
    \begin{array}{rrr}
        -12R_1: & -24 & -12\\
        R_3: & 3 & 7\\
        \cline{2-3}
        \text{(new) }R_3: & -21 & -5
    \end{array}
    \end{scriptsize}
]{-12R_1+R_3\rightarrow R_3}\left(\begin{array}{cc}
    2 & 1\\
    1 & -5\\
    -21 & -5
\end{array}\right)
\]
\end{document}

enter image description here