4

I would like to label my matrices with row operations. I am aware that this exists, but I am looking specifically for the style below.

enter image description here

My current code is as follows:

\documentclass{article}
\usepackage{amssymb}
\usepackage{amsmath}

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother

\begin{document}

\begin{align*}
&\sim
\begin{bmatrix}[ccc|c]
1 & 1 & -1 & 1\\
0 & 1 & k+2 & 1\\
0 & k-1 & 4 & 1
\end{bmatrix}
\end{align*}

\end{document}

Clarification: I am looking for code which reproduces the image above. I have updated the code to reflect this.

3
  • Welcome to TeX.SE.
    – Mico
    Commented Mar 15, 2020 at 8:44
  • Do you like code which reproduce showed image? So far your MWE is not related to it.
    – Zarko
    Commented Mar 15, 2020 at 8:46
  • Oops, my bad. I have updated my MWE to more closely resemble the image.
    – Haotian H.
    Commented Mar 15, 2020 at 8:49

3 Answers 3

5

Here's a solution that employs the basic LaTeX environment called array and doesn't require any additional packages.

enter image description here

\documentclass{article}
\begin{document}
\[
\sim \left[ \begin{array}{ccc|c}
       1 & 1   & -1  & 1 \\
       0 & 1   & k+2 & 1 \\
       0 & k-1 & 4   & 1 
     \end{array} \right]
     \begin{array}{l}
        \\
        R_2 \to R_2-2R_1 \\
        R_3 \to R_3- R_1
     \end{array}
\]
\end{document}
1
  • If you want the rows in the matrices to be spaced a bit more widely, I suggest you insert the instruction \renewcommand\arraystretch{1.2} immediately after \[. (The default value of \arraystretch is 1.)
    – Mico
    Commented Mar 15, 2020 at 8:59
5

Use nicematrix

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}

\begin{document}

\[
\begin{bNiceArray}[last-col]{ccc|c}
1 &  1  &  -1 & 1 & \\
0 &  1  & k+1 & 1 & R_2 \gets R_2-2R_1 \\
0 & k-1 &  4  & 1 & R_3 \gets R_3-R_1
\end{bNiceArray}
\]

\end{document}

enter image description here

You can also get a less prominent display of the operations.

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}

\begin{document}

\[
\begin{bNiceArray}[last-col,code-for-last-col=\scriptstyle]{ccc|c}
1 &  1  &  -1 & 1 & \\
0 &  1  & k+1 & 1 & R_2 \gets R_2-2R_1 \\
0 & k-1 &  4  & 1 & R_3 \gets R_3-R_1
\end{bNiceArray}
\]

\end{document}

enter image description here

2

Adding a matrix* environment on the right:

\documentclass{article}
\usepackage{array}
\usepackage{amssymb}
\usepackage{mathtools}

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother

\begin{document}

\begin{align*}
&\sim
\begin{bmatrix}[ccc|c]
1 & 1 & -1 & 1\\
0 & 1 & k+2 & 1\\
0 & k-1 & 4 & 1
\end{bmatrix}
\!
\begin{matrix*}[l]
 \\
 \scriptstyle R_{2}\to R_{2}-2R_{1} \\
\scriptstyle R_{3}\to R_{3}-R_{1}
\end{matrix*}
\end{align*}

\end{document} 

enter image description here

You must log in to answer this question.

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