1

what's wrong with my code? The usage of the foreach loop instead of the direct draw commands leads to an error that the path is not known. Do you have any suggestions?

Thanks a lot in advance!

! Package tikz Error: I do not know the path named `links 1'.

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
  \begin{tikzpicture}

    \draw [name path=links 1] (0,0) -- +(10:5cm);
    \draw [name path=links 2] (0,0) -- +(20:5cm);
    \draw [name path=links 3] (0,0) -- +(30:5cm);
    \draw [name path=rechts 1] (5,0) -- +(150:5cm);
    \draw [name path=rechts 2] (5,0) -- +(160:5cm);
    \draw [name path=rechts 3] (5,0) -- +(170:5cm);

% why can't I use the foreach-loops instead?

%   \foreach \angle/\num in {10/1,20/2,30/3}{%
%       \draw [name path=links \num] (0,0) -- +(\angle:5cm);
%   }
%
%   \foreach \angle/\num in {150/1,160/2,170/3}{%
%       \draw [name path=rechts \num] (5,0) -- +(\angle:5cm);
%   }

    \fill [name intersections={of=links 1 and rechts 1, name=a}] 
        (a-1) circle (2pt) node {};

    \fill [name intersections={of=links 1 and rechts 2, name=b}] 
        (b-1) circle (2pt) node {};

    \fill [name intersections={of=links 2 and rechts 2, name=c}] 
        (c-1) circle (2pt) node {};

  \end{tikzpicture}
\end{document}

enter image description here

  • 1
    Your code works without error for me with MikTeX – AndréC Oct 23 '18 at 14:26
  • Well, yes, it should, but if you remove the comment signs and put them instead to the drawing commands below, then I get the error message. Sorry for that misunderstanding. – Harald Lichtenstein Oct 23 '18 at 14:32
  • 1
    Replace name path by name path global in the foreach loops. – esdd Oct 23 '18 at 14:42
  • 1
    I had uncommented the lines and it worked – AndréC Oct 23 '18 at 14:42
  • 2
    It also works on my updated TeXLive2018 distribution, regardless of whether I compile pdflatex, xelatex or lualatex. And I do not need name path global to make it work. It also works if I use a loop to draw the bullets at the intersections: \foreach \X/\Y in {1/1,1/2,2/2} { \fill [name intersections={of={links \X} and {rechts \Y}, name=i-\X-\Y}] (i-\X-\Y-1) circle (2pt) node {}; }. – user121799 Oct 23 '18 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.