TeX - LaTeX Asked by Nivek on May 27, 2021
I’m looking for a solution concerning a foreach
-loop using the knots
package. I figured out that defining a foreach loop and using strands inside doesn’t give any output unless I’m using the draw option. But no knots are recognised since the red lines don’t seem to have an id. Look at the two pictures on the left.
foreach x in {2,3,4} { strand [draw,red,->] (1,x) -- (4,x); % instead of [red,->] }
Rearranging the loop gives nearly the output needed. But the option strand [red,->]
doesn’t execute all options to every strand. All strands are red, but only one of them has an arrow at the tip. Using the draft mode, you can see that there is only one strand created, which makes sense looking at the definition of the loop. Look at the two pictures on the right.
So my question is how to create separate strands within a foreach loop?
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 (wx) -- coordinate (ex)(4,x)
};
%
strand [thick,->] (2,1) -- (2,5);
strand [thick,->] (3,1) -- (3,5);
%flipcrossings {2}
end{knot}
%
end{tikzpicture}
end{document}
You can use a loop that does not start groups.
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]
%
edefx{1}
loop
edefx{thenumexprx+1}
strand [red,->]
(1,x) coordinate (wx) -- coordinate (ex)(4,x);
ifnumx<4repeat
%
strand [thick,->] (2,1) -- (2,5);
strand [thick,->] (3,1) -- (3,5);
%flipcrossings {2}
end{knot}
%
end{tikzpicture}
end{document}
Correct answer by user228539 on May 27, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP