![使用 foreach 时如何抑制链中的连接边?](https://linux22.com/image/377574/%E4%BD%BF%E7%94%A8%20foreach%20%E6%97%B6%E5%A6%82%E4%BD%95%E6%8A%91%E5%88%B6%E9%93%BE%E4%B8%AD%E7%9A%84%E8%BF%9E%E6%8E%A5%E8%BE%B9%EF%BC%9F.png)
如何使用和在下面的代码中移除/抑制从节点3
到节点的边?4
chains
join
我是否必须将其拆分foreach
成两个较小的?
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning, arrows.meta, chains}
\begin{document}
\begin{tikzpicture}[node distance = 1.00cm,
every node/.style = {draw, circle, fill = blue!20},
every join/.style = {->},
start chain = path]
\foreach \i in {1, ..., 7} {
\node [on chain, join] {\i};
}
\end{tikzpicture}
\end{document}
答案1
像这样?
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning, arrows.meta, chains}
\begin{document}
\begin{tikzpicture}[node distance = 1.00cm,
every node/.style = {draw, circle, fill = blue!20},
every join/.style = {->},
start chain = path]
\foreach \i in {1, ..., 7} {
\ifnum\i=4
\node [on chain] {\i};
\else
\node [on chain, join] {\i};
\fi
}
\end{tikzpicture}
\end{document}
或者
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning, arrows.meta, chains}
\begin{document}
\begin{tikzpicture}[node distance = 1.00cm,
every node/.style = {draw, circle, fill = blue!20, on chain},
every join/.style = {->},
start chain = path]
\foreach \i in {1, ..., 7} {
\ifnum\i=4
\node {\i};
\else
\node [join] {\i};
\fi
}
\end{tikzpicture}
\end{document}