0

My question is to get the following output using LaTeX. I'm using article class with amsmath package. I can of course get the matrices but not the form as appeared in the image. Any help in getting this done is much appreciated.

enter image description here

Quantas
  • 101

1 Answers1

3

One option is nicematrix.

\documentclass{article}
\usepackage{geometry}
\usepackage{mathtools}
\usepackage{nicematrix}
\begin{document}
\begin{align*}
  E_1&=
  \begin{bNiceArray}{rrr}[first-row,last-col]
\multicolumn{3}{c}{\mathclap{\textcolor{magenta}{\text{Elementary Matrix}}}}\\
        0 & 1 & 0 &\textcolor{magenta}{R_1\leftrightarrow R_2}\\
        1 & 0 & 0 & \\
        0 & 0 & 1 & \\
  \end{bNiceArray}
  &
  E_1^{-1}&=
  \begin{bNiceArray}{rrr}[first-row,last-col]
\multicolumn{3}{c}{\mathclap{\textcolor{magenta}{\text{Inverse Matrix}}}}\\
        0 & 1 & 0 &\textcolor{magenta}{R_1\leftrightarrow R_2}\\
        1 & 0 & 0 & \\
        0 & 0 & 1 & \\
  \end{bNiceArray}\\
  E_2&=
  \begin{bNiceArray}{rrr}[last-col]
        1 & 0 & 0 &\\
        0 & 1 & 0 & \\
        -2 & 0 & 1&
        \textcolor{magenta}{R_2+(-2)R_1\to R_3} \\
  \end{bNiceArray} 
  &
  E_2^{-1}&=
  \begin{bNiceArray}{rrr}[last-col]
        1 & 0 & 0 &\\
        0 & 1 & 0 & \\
        2 & 0 & 1 & \textcolor{magenta}{R_2+(2)R_1\to R_3} \\
 \end{bNiceArray}  \\
  E_3&=
  \begin{bNiceArray}{rrr}[last-col]
        1 & 0 & 0 &\\
        0 & 1 & 0 & \\
        0 & 0 & \frac{1}{2} &
        \textcolor{magenta}{(\tfrac{1}{2})R_3\to R_3} \\
  \end{bNiceArray} 
  &
  E_3^{-1}&=
  \begin{bNiceArray}{rrr}[last-col]
        1 & 0 & 0 &\\
        0 & 1 & 0 & \\
        0 & 0 & 2 & \textcolor{magenta}{(2)R_3\to R_3} 
  \end{bNiceArray} \\
\end{align*}
\end{document}

enter image description here

Another option is blkarray.

\documentclass{article}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{blkarray}
\usepackage{bigstrut}
\usepackage{xcolor}
\begin{document}
\begin{align*}
  E_1&=
  \begin{array}{@{}l@{}}
  \textcolor{magenta}{\text{Elementary Matrix}}\\
  \begin{blockarray}{[rrr]l}
        \bigstrut[t]0 & 1 & 0 &\textcolor{magenta}{R_1\leftrightarrow R_2}\\
        1 & 0 & 0 & \\
        0 & 0 & 1 & \\
  \end{blockarray} 
  \end{array}
  &
  E_1^{-1}&=
  \begin{array}{@{}l@{}}
  \textcolor{magenta}{\text{Inverse Matrix}}\\
  \begin{blockarray}{[rrr]l}
        \bigstrut[t]0 & 1 & 0 &\textcolor{magenta}{R_1\leftrightarrow R_2}\\
        1 & 0 & 0 & \\
        0 & 0 & 1 & \\
  \end{blockarray}
  \end{array} \\
  E_2&=
  \begin{blockarray}[t]{[rrr]l}
        1 & 0 & 0 \bigstrut[t]&\\
        0 & 1 & 0 & \\
        -2 & 0 & 1&
        \textcolor{magenta}{R_2+(-2)R_1\to R_3} 
  \end{blockarray} 
  &
  E_2^{-1}&=
  \begin{blockarray}[t]{[rrr]l}
        \bigstrut[t]1 & 0 & 0 &\\
        0 & 1 & 0 & \\
        2 & 0 & 1 & \textcolor{magenta}{R_2+(2)R_1\to R_3} \\
  \end{blockarray} \\
  E_3&=
  \begin{blockarray}[t]{[rrr]l}
        \bigstrut[t]1 & 0 & 0 &\\
        0 & 1 & 0 & \\
        0 & 0 & \frac{1}{2} &
        \textcolor{magenta}{(\tfrac{1}{2})R_3\to R_3} \\
  \end{blockarray} 
  &
  E_3^{-1}&=
  \begin{blockarray}[t]{[rrr]l}
        \bigstrut[t]1 & 0 & 0 &\\
        0 & 1 & 0 & \\
        0 & 0 & 2 & \textcolor{magenta}{(2)R_3\to R_3} 
  \end{blockarray} \\
\end{align*}
\end{document}

enter image description here

F. Pantigny
  • 40,250
  • This is beautiful ! Much appreciated. – Quantas Apr 27 '20 at 05:21
  • @Quantas You're welcome! –  Apr 27 '20 at 05:22
  • 1
    For the solution with nicematrix it's possible to put \NiceMatrixOptions{code-for-first-row = \color{magenta},code-for-last-col = \color{magenta}} and avoid putting \textcolor{magenta} each time. – F. Pantigny Apr 27 '20 at 06:20
  • @F.Pantigny Thanks for the heads up. Yes, that's a good suggestion. (I had the blkarray first and then copied the code from this answer to the other one.) –  Apr 27 '20 at 06:21
  • @Schrödinger'scat, when I ran your first code it gives me an error: ! Package nicematrix Error: Your version of LaTeX (especially expl3) is too (nicematrix) old. You can go on but you will probably have (nicematrix) other errors if you use the functionalities of (nicematrix) nicematrix. Type to continue.

    Could you please let me know how to get rid of this. Thanks.

    – Quantas Apr 30 '20 at 01:39
  • @Quantas I think that the only reasonable way to get rid of this is to update your TeX installation. The author of nicematrix, who is the author of the third comment, made substantial efforts to further improve their nice package, so it is best to use the most recent version. (And I would not even know how to install an older version on my machine.) –  Apr 30 '20 at 01:43
  • I did install the new version 5.0.4 but still the problem previals. Anyway, I'll check. Glad to know that @F.Pantigny, is the author of the code. – Quantas Apr 30 '20 at 01:51
  • @Quantas I think that nicematrix complains that your expl3 code/package is too old. Unless you have already done so, you may want to update the complete TeX installation. On my TeXLive 2020 installation this runs without problems. –  Apr 30 '20 at 02:02
  • @Quantas: If you really want an older version of nicematrix, send me an email: fpantigny@wanadoo.fr – F. Pantigny Apr 30 '20 at 09:58