答案1
由于这可以非常快速地完成(除了输入条目),因此这里有一个带有 的版本nicematrix
。不过,我同意 @fractal 的观点,认为这不是该网站的目的。
\documentclass{article}
\usepackage[fleqn]{amsmath}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{calc, fit}
\begin{document}
\[\mathbf{B}=\left[\;\begin{NiceArray}{cccc|c}[name=B]
1 & 0 & 2 & 0 & -1 \\
0 & 1& 0 & 3 & 4\\
0 & 0& 0 & 1 & 2\\
0 & 0& 0 & 0 & 0\\
\end{NiceArray}\;\right]
\begin{tikzpicture}[remember picture, overlay,
c/.style={fit={(B-#1)},circle,draw,thick,inner sep=0.6pt,node contents={}}]
\path foreach \X in {1-1,2-2,3-4} {node [c=\X]};
\draw[very thin,gray] let \p1=($(B-1-2.south west)-(B-2-1.north east)$) in
([xshift=-\x1/2,yshift=-2*\y1/3]B-1-1.south west)
-| ([xshift=-\x1/2,yshift=-2*\y1/3]B-2-2.south west)
-| ([xshift=-\x1/2,yshift=-2*\y1/3]B-3-4.south west)
-- ([xshift=\x1/3,yshift=-2*\y1/3]B-3-4.south east)
([xshift=-\x1/2,yshift=-2*\y1/3]B-3-5.south west)
-- ([xshift=\x1/2,yshift=-2*\y1/3]B-3-5.south east);
\end{tikzpicture}
\]
\end{document}
有无数种替代方案,有些方案需要更少的软件包,但代价是控制力会减弱,其他人会批评这里的间距(但这是为了重现屏幕截图)等等。这样的矩阵是否真的能帮助读者理解发生了什么,这个问题已经偏离主题了,这只是说,如果你真的需要,很容易创建这样的东西。
答案2
使用新circledsteps
包的解决方案hhline
:
\documentclass[svgnames, table]{article}
\usepackage{amsmath}%
\usepackage{array, hhline}
\usepackage{circledsteps, tikz}
\tikzset{/csteps/inner ysep=6pt, /csteps/inner xsep=6pt}
\begin{document}
\[
\setlength{\extrarowheight}{3pt}
\mathbf {B} = \begin{bmatrix}\begin{array}{@{}cccc|c@{}}
\Circled{\textbf{1}} & 0 & 2 & 0 & -1 \\[0.5ex]\noalign{\vspace*{-0.4pt}}
\hhline{>{\arrayrulecolor{Gainsboro}}-~>{\arrayrulecolor{black}~~~}}
\multicolumn{1}{@{}c!{\color{Gainsboro}\vrule}}{0 }& \Circled{\textbf{1}} &3 & 0 & 4 \\[0.2ex]
\hhline{~>{\arrayrulecolor{Gainsboro}}|--~>{\arrayrulecolor{black}}~}\noalign{\vspace*{-0.4pt}}
0 & 0 & \multicolumn{1}{c!{\color{Gainsboro}\vrule}}{0} & \Circled{\textbf{1}} &2 \\[0.2ex]
\hhline{~~~>{\arrayrulecolor{Gainsboro}}|->{\arrayrulecolor{black}}|>{\arrayrulecolor{Gainsboro}}-}
0 & 0 & 0 & \multicolumn{1}{c!{\color{black}\vrule}}{0 } & 0
\end{array}
\end{bmatrix} \]
\end{document}
答案3
与。{NiceTabular}
nicematrix
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
$\mathbf{B} =
\begin{bNiceArray}{cccc|c}[left-margin=2pt]
1 & 0 & 2 & 0 & -1 \\
0 & 1 & 0 & 3 & 4 \\
0 & 0 & 0 & 1 & 2 \\
0 & 0 & 0 & 0 & 0
\CodeAfter
\begin{tikzpicture} [shorten < = 2pt , shorten > = 2pt, radius = 1.5mm]
\draw (1-1) circle ;
\draw (2-2) circle ;
\draw (3-4) circle ;
\draw [very thin] (2-|1) -| (3-|2) -| (4-|4) -- (4-|5) ;
\draw [very thin, shorten > = 4pt ] (4-|5) -- (4-|6) ;
\end{tikzpicture}
\end{bNiceArray}$
\end{document}