我如何在此矩阵中添加交换箭头?
这是一张图片来展示我想要实现的目标
\documentclass[10pt,letterpaper]{article}
\usepackage[left=8mm,top=6mm,bottom=6mm]{geometry}
\usepackage{nccmath}
\usepackage{soul}
\usepackage[normalem]{ulem}
\begin{document}
\[
\mbox{
\Large$
\begin{bmatrix}
1 & 1 &2\\
1&1&3\\
2&1&4
\end{bmatrix}
$}
\]
\end{document}
答案1
一个简单的解决方案是pstricks
:矩阵中的相关条目是\rnode
通过节点连接(\ncarc
)链接起来的:
\documentclass[10pt,letterpaper, svgnames]{article}
\usepackage[left=8mm,top=6mm,bottom=6mm]{geometry}
\usepackage{nccmath}
\usepackage{soul}
\usepackage[normalem]{ulem}
\usepackage{pst-node}
\begin{document}
\[ \setlength{\arraycolsep}{6pt}\renewcommand{\arraystretch}{1.1}
\mbox{
\Large$
\begin{bmatrix}
1 & \rnode{a}{1} &\rnode{b}{2}\\
\rnode{c}{1}&1&\rnode{d}{3}\\
\rnode{e}{2}&\rnode{f}{1}&4
\end{bmatrix}
$}
\psset{arrows=<->, arrowinset=0.12, nodesepA=1pt, nodesepB=0pt, arcangle=30}
\ncarc[linecolor=Gold]{c}{a}\ncarc[linecolor=Crimson]{e}{b}\ncarc[linecolor=Brown]{f}{d}
\]
\end{document}
答案2
一种可能性是使用该tikzmark
库:
\documentclass[10pt,letterpaper]{article}
\usepackage[left=8mm,top=6mm,bottom=6mm]{geometry}
\usepackage{nccmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
tikzmark} % new
\begin{document}
{\Large
\[
\begin{bmatrix}
1 & \tikzmarknode{a1}{1} & \tikzmarknode{b1}{2}\\
\tikzmarknode{a2}{1} & 1 &\tikzmarknode{c1}{3}\\
\tikzmarknode{b2}{2} & \tikzmarknode{c2}{1} & 4
\end{bmatrix}
\begin{tikzpicture}[overlay,remember picture,
>={Straight Barb[angle=60:2pt 2]}
]
\draw[<->, thick, red, semitransparent]
(a1) edge (a2)
(b1) edge (b2)
(c1) to (c2);
\draw[<->, thick, blue, semitransparent]
(a1) edge[bend right] (a2)
(b1) edge[bend right] (b2)
(c1) to[bend right] (c2);
\end{tikzpicture}
\]
}
\end{document}
您需要选择\draw[...]
您更喜欢的箭头(红色或蓝色)并删除其他箭头。
答案3
您可以使用nicematrix
它将在矩阵的每个单元下创建一个 PGF/Tikz 节点。然后,您必须使用 Tikz 绘制箭头。
\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
$\begin{bNiceMatrix}[name=A,columns-width=7mm]
1 & 1 & 2 \\[1ex]
1 & 1 & 3 \\[1ex]
2 & 1 & 4 \\
\end{bNiceMatrix}$
\begin{tikzpicture}[remember picture, overlay,
every path/.style = { <->, thick, blue , bend right = 15, } ]
\draw (A-1-2) to (A-2-1) ;
\draw (A-2-3) to (A-3-2) ;
\draw (A-1-3) to (A-3-1) ;
\end{tikzpicture}
\end{document}
答案4
也许作为 TikZ 矩阵:
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[
BendArrow/.style={<->, thick, red, rounded corners=3pt},
]
\matrix (m) [matrix of math nodes, nodes in empty cells,
nodes={inner sep=0pt,
},
column sep=1.5em, row sep=1.5em,
left delimiter={[},right delimiter={]}
]{
1 & 1 & 2 \\
1 & 1 & 3 \\
2 & 1 & 4 \\
};
\foreach \Start/\End in {1-2/2-1, 1-3/3-1, 2-3/3-2}{
\draw[BendArrow] (m-\Start.west) -- ([xshift=-0.5em]m-\Start.west) -- ([xshift=-0.75em]m-\End.west) -- (m-\End.west);
}
% Another method:
%\draw[BendArrow] (m-1-2.west) to[bend right=90] (m-2-1.west);
\end{tikzpicture}
\end{document}