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 Answers3

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}
Mico
  • 506,678
  • 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 Mar 15 '20 at 08: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

F. Pantigny
  • 40,250
egreg
  • 1,121,712
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

Bernard
  • 271,350