我已经申请了以下答案我应该如何绘制链接列表,每个节点都由附加节点指向(我在答案中使用了完全相同的代码)。但我无法在单元格之间绘制箭头。
我想知道如何在底部单元格之间画箭头:
例子:
箭头经过内箭头上方的示例(假设有一个单元格):
如果箭头存在于另一个箭头已经进入的单元格中,它们会相互覆盖,是否可以移动它们,这样它们就不会相互覆盖,同时保持它们相同的高度。
使用以下代码:
\coordinate[below=of m-3-7](aux);
\draw[->](m-5-7)--(aux)-|(m-5-5);
\coordinate[below=of m-3-5](aux);
\draw[->](m-5-5)--(aux)-|(m-5-3);
但我希望各行不要互相覆盖,例如:
答案1
\documentclass[tikz,margin=3]{standalone}
\usepackage{sansmath}
\usetikzlibrary{fit,matrix,positioning,shadows, calc}
\begin{document}
\begin{tikzpicture}[font=\sffamily\sansmath,
square/.style={minimum size=1cm,draw,fill=white,drop shadow},
f/.style={fill=orange!20,draw=orange},
v2/.style={-stealth,very thick,yellow!65!black}]
\matrix[matrix of math nodes,row sep=-\pgflinewidth,column sep=1.5em,
cells={nodes={square,
text depth=0.25ex,text height=1em}},
row 1/.style={nodes=f}] (m){
0 & 4 & 10 \\[2em]
-16 & -16 & -16\\
3 & 10 & 15\\
|[f]|4 & |[f]|10 & /\\
};
%
\node[draw,dashed,inner sep=1em,fit=(m-1-1)(m-1-3)](f){};
%
\node[square,right=3em of m-1-3] (t){tail};
%
\foreach \x[count=\y] in {mapping,value,point,next}
{\draw \ifnum\y=1 (f.west)
\else
(m-\y-1.west)\fi -- ++ (-2em,0) node[left]{\x};}
%
\draw[v2] (t) -- (m-1-3);
\foreach \x in {1,2,3}
{\draw[v2] (m-1-\x) -- (m-2-\x);}
\coordinate[below=of m-4-1](aux);
\draw[v2](m-4-1)--(aux)-|(m-4-3);
\end{tikzpicture}
\end{document}
改变最后两行
\coordinate[below=of m-4-2](aux);
\draw[v2](m-4-2)--(aux)-|(m-4-3);
会给
若要在第四行中放置一个带箭头的附加节点,请添加以下代码
\node[square,right=3em of m-4-3] (q){};
\coordinate[below=1.5cm of m-4-1](auxx);
\draw[v2](m-4-1)--(auxx)-|(q);
编辑新答案
\documentclass[tikz,margin=3]{standalone}
\usepackage{sansmath}
\usetikzlibrary{fit,matrix,positioning,shadows, calc}
\begin{document}
\begin{tikzpicture}[font=\sffamily\sansmath,
square/.style={minimum size=1cm,draw,fill=white,drop shadow},
f/.style={fill=orange!20,draw=orange},
v2/.style={-stealth,very thick,yellow!65!black}]
\matrix[matrix of math nodes,row sep=-\pgflinewidth,column sep=1.5em,
cells={nodes={square,
text depth=0.25ex,text height=1em}},
row 1/.style={nodes=f}] (m){
0 & 4 & 10 \\[2em]
-16 & -16 & -16\\
3 & 10 & 15\\
|[f]|4 & |[f]|10 & /\\
};
%
\node[draw,dashed,inner sep=1em,fit=(m-1-1)(m-1-3)](f){};
%
\node[square,right=3em of m-1-3] (t){tail};
%
\foreach \x[count=\y] in {mapping,value,point,next}
{\draw \ifnum\y=1 (f.west)
\else
(m-\y-1.west)\fi -- ++ (-2em,0) node[left]{\x};}
%
\draw[v2] (t) -- (m-1-3);
\foreach \x in {1,2,3}
{\draw[v2] (m-1-\x) -- (m-2-\x);}
\coordinate[below=of m-4-1](aux);
\draw[v2](m-4-1)--(aux)-|(m-4-3);
\draw[v2](m-4-1.east)--(m-4-2.west);
\draw[v2]($(m-4-1.south)+(1ex,0ex)$) -- ($(m-4-1.south)+(1ex,-3ex)$)-|($(m-4-2.south)$);
\draw[v2]($(m-4-2.south)+(1ex,0ex)$) -- ($(m-4-2.south)+(1ex,-3ex)$)-|($(m-4-3.south)+(-2ex,0pt)$);
\end{tikzpicture}
\end{document}