Tikz-knots: foreach ループ内で別々のストランドを定義する

Tikz-knots: foreach ループ内で別々のストランドを定義する

foreachパッケージを使用したループに関する解決策を探していますknots。 foreach ループを定義し、内部でストランドを使用すると、draw オプションを使用しない限り出力が得られないことがわかりました。ただし、赤い線には ID がないため、ノットは認識されません。左側の 2 つの画像をご覧ください。

\foreach \x in {2,3,4} {
\strand [draw,red,->] (1,\x) -- (4,\x); % instead of [red,->]
}

ループを並べ替えると、ほぼ必要な出力が得られます。ただし、オプションは\strand [red,->]すべてのストランドにすべてのオプションを実行するわけではありません。すべてのストランドは赤ですが、先端に矢印があるのはそのうちの 1 つだけです。ドラフト モードを使用すると、ループの定義を見ると、作成されたストランドは 1 つだけであることがわかります。右側の 2 つの画像をご覧ください。

私の質問は、foreach ループ内で別々のストランドを作成する方法です。

\documentclass[tikz,border=5mm]{standalone}
%\documentclass[convert={density=1200,size=4320x3200,outext=.png}]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{knots}
%
\begin{document}
\begin{tikzpicture}[scale=1.0,>=latex']
%
\draw[fill=white] (0,0) rectangle (5,6);
%
\begin{knot}[ %draft mode=crossings,
clip width=5,
clip radius=6pt]
%
\strand [red,->]
    \foreach \x in {2,3,4} {
    (1,\x) coordinate (w\x) -- coordinate (e\x)(4,\x)
    };
%
\strand [thick,->] (2,1) -- (2,5);
\strand [thick,->] (3,1) -- (3,5);
%\flipcrossings {2}
\end{knot}
%
\end{tikzpicture}
\end{document}

上部ループ (非ドラフト/ドラフト モード) - 完全なコードからのループ (非ドラフト/ドラフト モード)

答え1

グループを開始しないループを使用できます。

\documentclass[tikz,border=5mm]{standalone}
%\documentclass[convert={density=1200,size=4320x3200,outext=.png}]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{knots}
%
\begin{document}
\begin{tikzpicture}[scale=1.0,>=latex']
%
\draw[fill=white] (0,0) rectangle (5,6);
%
\begin{knot}[ %draft mode=crossings,
clip width=5,
clip radius=6pt]
%
\edef\x{1}
\loop
\edef\x{\the\numexpr\x+1}
\strand [red,->]
    (1,\x) coordinate (w\x) -- coordinate (e\x)(4,\x);
\ifnum\x<4\repeat
%
\strand [thick,->] (2,1) -- (2,5);
\strand [thick,->] (3,1) -- (3,5);
%\flipcrossings {2}
\end{knot}
%
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報