행렬의 열 주위에 색칠된 상자

행렬의 열 주위에 색칠된 상자

다음과 같은 화살표와 텍스트가 있는 행렬의 열 주위에 색상 상자를 그리는 방법은 무엇입니까?

여기에 이미지 설명을 입력하세요

지금까지 내가 가지고 있는 코드는 다음과 같습니다.

\documentclass[11pt]{book}

\usepackage{amsmath,amsfonts,amssymb,amsthm}

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

\usepackage{tikz} 

\begin{document}

\begin{equation}
\begin{bmatrix}[cccc|c]
  1 & 0 & -1 & 0 & 0 \\
  0 & 1 & 2 & 0 & 0 \\
  0 & 0 & 0 & 1 & 0
\end{bmatrix}\\
\end{equation}

\end{document} 

답변1

가장 간단한 방법은 행렬을 TikZ 행렬로 작성하고 원하는 열 프레임을 추가하고 여기에 메모하는 것입니다.

여기에 이미지 설명을 입력하세요

\documentclass[11pt]{book}
    \usepackage{amsmath,amsfonts,amssymb,amsthm}
    \usepackage{tikz}
\usetikzlibrary{arrows.meta,bending,matrix,positioning}

    \begin{document}
\begin{equation}
\begin{tikzpicture}[
    node distance=1mm and 0mm,
    baseline]
\matrix (M1) [matrix of nodes,{left delimiter=[},{right delimiter=]}]
{
  1 & 0 & -1 & 0 & 0 \\
  0 & 1 & 2  & 0 & 0 \\
  0 & 0 & 0  & 1 & 0 \\
};
\draw   (M1-1-4.north east) -- (M1-3-4.south east);
\draw[red,very thick] 
        (M1-1-3.north west) -| (M1-3-3.south east) -| (M1-1-3.north west);
\node (fv) [below right=of M1.south east,align=left,
            font=\sffamily\bfseries] {free\\variable};
\draw[blue!60,very thick,shorten >=1mm,-{Stealth[bend]}] 
        (fv.west) to [out=180,in=270] (M1-3-3.south);
\end{tikzpicture}
\end{equation}
    \end{document}

관련 정보