将两个节点连接起来很容易。我有一个青色节点与圆形节点 X 连接。
现在我有一个链组成圆形节点,我想将洋红色节点框与链中的圆形 7 连接起来。
有人知道我该如何处理链中的节点吗?
梅威瑟:
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary {chains}
\begin{document}
\begin{tikzpicture}[growth dir/.store in=\tikzgrowthdir,
growth dist/.store in=\tikzgrowthdist,growth dir=-90,growth dist=0.1]
\begin{scope}[start chain=going {at=(\tikzchainprevious.\tikzgrowthdir),
shift=(\tikzgrowthdir:\tikzgrowthdist),anchor=180+\tikzgrowthdir},
nodes={on chain,circle,draw,draw,minimum size=1cm}]
\foreach \X [count=\Y] in {1,2,3,4,5,6,7,8,9,10,11,12,13,14}
{\ifnum\numexpr\Y>3\relax
\tikzset{growth dir=-135}
\fi
\ifnum\numexpr\Y>5\relax
\tikzset{growth dir=-90}
\fi
\ifnum\numexpr\Y>10\relax
\tikzset{growth dir=-135}
\fi
\node {\X};}
\end{scope}
% node connection
\node(A) [draw=cyan!20,fill=cyan!20,text width=3cm, rounded corners] at (-4,0) {Description};
\node(X) [draw,circle] at (-2,-2) {X};
\draw[color=cyan!20, line width=1mm] (A.south) |- (X.west);
\node(A) [draw=magenta!20,fill=magenta!20,text width=3cm, rounded corners] at (-4,-3) {Description};
\end{tikzpicture}
\end{document}
答案1
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary {chains}
\begin{document}
\begin{tikzpicture}[growth dir/.store in=\tikzgrowthdir,
growth dist/.store in=\tikzgrowthdist,growth dir=-90,growth dist=0.1]
\begin{scope}[start chain=going {at=(\tikzchainprevious.\tikzgrowthdir),
shift=(\tikzgrowthdir:\tikzgrowthdist),anchor=180+\tikzgrowthdir},
nodes={on chain,circle,draw,draw,minimum size=1cm}]
\foreach \X [count=\Y] in {1,2,3,4,5,6,7,8,9,10,11,12,13,14}
{\ifnum\numexpr\Y>3\relax
\tikzset{growth dir=-135}
\fi
\ifnum\numexpr\Y>5\relax
\tikzset{growth dir=-90}
\fi
\ifnum\numexpr\Y>10\relax
\tikzset{growth dir=-135}
\fi
\node (n\X){\X};}
\end{scope}
% node connection
\node(A) [draw=cyan!20,fill=cyan!20,text width=3cm, rounded corners] at (-4,0) {Description};
\node(X) [draw,circle] at (-2,-2) {X};
\draw[color=cyan!20, line width=1mm] (A.south) |- (X.west);
\node(A) [draw=magenta!20,fill=magenta!20,text width=3cm, rounded corners] at (-4,-3) {Description};
\draw[color=red!70, line width=1mm] (A.south) |- (n7.west);
\end{tikzpicture}
\end{document}