![矩陣中一列周圍的彩色框](https://rvso.com/image/327782/%E7%9F%A9%E9%99%A3%E4%B8%AD%E4%B8%80%E5%88%97%E5%91%A8%E5%9C%8D%E7%9A%84%E5%BD%A9%E8%89%B2%E6%A1%86.png)
我怎麼能在矩陣中的一列周圍繪製一個帶有箭頭和文字的彩色框,如下所示:
這是我迄今為止的程式碼:
\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}