答案1
你可以让 Ti钾Z 会执行这些操作,无论您是手动还是通过 定位节点chain
。您只需拨打一些适当的to path
。此示例中的重要成分是\ifdim\n1>2pt
,它会根据起始和目标的级别是否(大致)相同来更改路径。\n1
是垂直距离,已用 测量calc
。显然,您可以进行许多类似的测试以使事情自动化。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,calc,chains,shapes.multipart}
\begin{document}
\begin{tikzpicture}[2p/.style={rectangle split,rectangle split horizontal,
rectangle split parts=2,rectangle split part fill={none,gray!50},draw},
hconnect/.style={semithick,{Circle[width=2pt,length=2pt]}-Stealth,to path={
let \p1=($(\tikztotarget)-(\tikztostart)$),\n1={abs(\y1)},
\n3={min(abs(\y1/2),2pt)}
in
\ifdim\n1>2pt
(\tikztostart.two east-|\tikztostart.two south)[rounded corners=\n3]
-| ($(\tikztotarget)!0.5!(\tikztostart)$) |- (\tikztotarget)
\else
(\tikztostart.two east-|\tikztostart.two south) -- (\tikztotarget)
\fi
}}]
\begin{scope}[yshift=2cm]
\node[2p](A){~10~~};
\node[2p,right=2em of A](B){~20~~};
\node[2p,right=2em of B,yshift=1em](C){~30~~};
\draw[hconnect] (A) to (B);
\draw[hconnect] (B) to (C);
\end{scope}
%
\begin{scope}[start chain=B going right,
nodes={2p,on chain,join=by hconnect}]
\path node{~10~~} node{~20~~} node[yshift=1em]{~30~~}
node[yshift=-1em]{~40~~} node{~50~~} node{~60~~};
\end{scope}
\path (B-6.two east-|B-6.two south)
node[circle,draw,inner sep=1.5pt,path picture={
\draw(path picture bounding box.north east) --
(path picture bounding box.south west);}]{};
\end{tikzpicture}
\end{document}