使用 foreach 时如何抑制链中的连接边?

使用 foreach 时如何抑制链中的连接边?

如何使用和在下面的代码中移除/抑制从节点3到节点的边?4chainsjoin

我是否必须将其拆分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}

相关内容