如何实现如图所示的类似箭头?
箭头的主要原因
a(2,1) -> a(1,3), a(3,1) -> a(1,4) 等等。或者至少如何使它们位于表格顶部,但又使其看起来可读。
\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[>=stealth]
\matrix (A) [matrix of nodes,row sep=3mm,column sep=3mm,nodes in empty cells]
{
$a_{11}$ & $a_{12}$ & $a_{13}$ & $a_{14}$ & $a_{15}$ & $\dots$ \\
$a_{21}$ & $a_{22}$ & $a_{23}$ & $a_{24}$ & $a_{25}$ & \\
$a_{31}$ & $a_{32}$ & $a_{33}$ & $a_{34}$ & $a_{35}$ & \\
$a_{41}$ & $a_{42}$ & $a_{43}$ & $a_{44}$ & $a_{45}$ & \\
$a_{51}$ & $a_{52}$ & $a_{53}$ & $a_{54}$ & $a_{55}$ & \\
$\vdots$ & & & & & $\ddots$ \\
};
\begin{scope}[thick,black,->]
\draw (A-1-1)--(A-1-2);
\draw (A-1-2)--(A-2-2);
\draw (A-2-2)--(A-2-1);
%\draw (A-2-1)--(A-1-3);
\draw (A-1-3)--(A-2-3);
\draw (A-2-3)--(A-3-3);
\draw (A-3-3)--(A-3-2);
\draw (A-3-2)--(A-3-1);
%\draw (A-3-1)--(A-1-4);
% etc.
\end{scope}
\end{tikzpicture}
\end{document}
答案1
您可以使用库对坐标进行一些简单的计算calc
。您可以选择手动方式(注释)或使用宏\turnArrow
。不用说,您可以编辑它们两者。
\documentclass[border=10mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}
\newcommand\turnArrow[2]{
\draw (A-#1-1)
-- +($0.25*(A-1-1)-0.25*(A-1-#2)$)
-- ($1.5*(A-1-1)-0.25*(A-1-#2)-0.25*(A-#2-1)+(0,0.5em)$)
-- ($(A-1-#2)+0.25*(A-1-1)-0.25*(A-#2-1)+(0,0.5em)$)
--(A-1-#2)
;
}
\begin{document}
\begin{tikzpicture}[>=stealth]
\matrix (A) [matrix of nodes,row sep=3mm,column sep=3mm,nodes in empty cells]
{
$a_{11}$ & $a_{12}$ & $a_{13}$ & $a_{14}$ & $a_{15}$ & $\dots$ \\
$a_{21}$ & $a_{22}$ & $a_{23}$ & $a_{24}$ & $a_{25}$ & \\
$a_{31}$ & $a_{32}$ & $a_{33}$ & $a_{34}$ & $a_{35}$ & \\
$a_{41}$ & $a_{42}$ & $a_{43}$ & $a_{44}$ & $a_{45}$ & \\
$a_{51}$ & $a_{52}$ & $a_{53}$ & $a_{54}$ & $a_{55}$ & \\
$\vdots$ & & & & & $\ddots$ \\
};
\begin{scope}[thick,black,->]
\draw (A-1-1)--(A-1-2);
\draw (A-1-2)--(A-2-2);
\draw (A-2-2)--(A-2-1);
%\draw (A-2-1)
% -- +(-1.5em,0)
% -- ($(A-1-1)+(-1.5em,1.5em)$)
% -- ($(A-1-3)+(0,1.5em)$)
% -- (A-1-3);
\turnArrow{2}{3}
\draw (A-1-3)--(A-2-3);
\draw (A-2-3)--(A-3-3);
\draw (A-3-3)--(A-3-2);
\draw (A-3-2)--(A-3-1);
%\draw (A-3-1)
% -- +(-2em,0)
% -- ($(A-1-1)+(-2.0em,2.0em)$)
% -- ($(A-1-4)+(0,2.0em)$)
% -- (A-1-4);
\turnArrow{3}{4}
\turnArrow{4}{5}
\turnArrow{5}{6}
\end{scope}
\end{tikzpicture}
\end{document}