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

1

1 Answer 1

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

9
  • This is beautiful ! Much appreciated.
    – Quantas
    Apr 27, 2020 at 5:21
  • @Quantas You're welcome!
    – user194703
    Apr 27, 2020 at 5: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. Apr 27, 2020 at 6: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.)
    – user194703
    Apr 27, 2020 at 6: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 <return> to continue. Could you please let me know how to get rid of this. Thanks.
    – Quantas
    Apr 30, 2020 at 1:39

You must log in to answer this question.

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