答案1
如果您做了一些准备来获得形状和额外的垂直和/或水平线以及虚线,您可以使用chains
或matrix
库来轻松绘制这些。 的优点chains
是您不必明确绘制水平箭头, 的优点matrix
是您不需要node
经常输入。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,chains,matrix}
\tikzset{c/.style={circle,draw,minimum size=4em,text width=2em,align=center},
h/.style={path picture={
\draw ([yshift=1em]path picture bounding box.west)
-- ([yshift=1em]path picture bounding box.east)
([yshift=-1em]path picture bounding box.west)
-- ([yshift=-1em]path picture bounding box.east);}},
v/.style={path picture={
\draw ([xshift=-1em]path picture bounding box.north east)
-- ([xshift=-1em]path picture bounding box.south east)
(path picture bounding box.west)
-- ([xshift=-1em]path picture bounding box.east);}},
dt/.style={append after command={
(\tikzlastnode.center) ++ (-0.7ex,1.2em) edge ++(1.4ex,1.4ex)}},
db/.style={append after command={
(\tikzlastnode.center) ++ (-0.7ex,-1.2em) edge ++(1.4ex,-1.4ex)}},
dr/.style={append after command={
(\tikzlastnode.center) ++ (1.2em,-0.7ex) edge ++(1.4ex,1.4ex)}},
arj/.style={-Stealth}}
\begin{document}
\begin{tikzpicture}
\path[start chain=R1 going right,
nodes={c,on chain,join=by arj}]
node[h,dt,alias=1]{1}
node[v]{1\\[1ex] 10} node[v]{2\\[1ex] 8} node[v,dr]{3\\[1ex] 4};
\path[start chain=R2 going right,
nodes={c,on chain,join=by arj}]
node[h,below=of 1,alias=2]{2}
node[v]{2\\[1ex] 8} node[v]{1\\[1ex] 3} node[v]{4\\[1ex] 5}
node[v,dr]{3\\[1ex] 6};
\path[start chain=R3 going right,
nodes={c,on chain,join=by arj}]
node[h,below=of 2,alias=3,db]{3}
node[v]{1\\[1ex] 4} node[v]{2\\[1ex] 7} node[v,dr]{4\\[1ex] 3};
\path[arj] (1.-120) edge (2.120) (2.60) edge (1.-60)
(2.-120) edge (3.120) (3.60) edge (2.-60) ;
\end{tikzpicture}
\begin{tikzpicture}
\matrix[matrix of nodes,nodes={c,anchor=center},column sep=1cm,row sep=1cm] (m){
|[h,dt,alias=1]|{1} & |[v]|{1\\[1ex] 10} & |[v]|{2\\[1ex] 8} & |[v,dr]|{3\\[1ex] 4}\\
|[h,alias=2]|{2} & |[v]|{2\\[1ex] 8} & |[v]|{1\\[1ex] 3} & |[v]|{4\\[1ex] 5} & |[v,dr]|{3\\[1ex] 6} \\
|[h,alias=3,db]|{3} & |[v]|{1\\[1ex] 4} & |[v]|{2\\[1ex] 7} & |[v,dr]|{4\\[1ex] 3} \\
};
\path[arj] (1.-120) edge (2.120) (2.60) edge (1.-60)
(2.-120) edge (3.120) (3.60) edge (2.-60)
foreach \Z in {1,2,3} {foreach \X[count=\Y] in {2,3,4}
{ (m-\Z-\Y) edge (m-\Z-\X)}}
(m-2-4) edge (m-2-5);
\end{tikzpicture}
\end{document}