Menu

#307 foreach clashes with "node contents" option

v1.0 (example)
closed-invalid
nobody
None
5
2015-08-03
2014-04-16
Ignasi
No

It's not possible to draw nodes through \foreach if nodes have node contents option.

Minimal not working example (with TikZ 3.0)

%---------------------------------------
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}

\foreach \i in {1,2,3}
\node[node contents=a] at (\i,0) ;

\end{tikzpicture}
\end{document}
%---------------------------------------

It finishes with:


! Use of \@next doesn't match its definition.
\pgffor@body ->\node [node contents=a] at
(\i ,0) ;
l.6 \node[node contents=a] at (\i,0) ;

?

Complete .log file is attached

1 Attachments

Discussion

  • percusse

    percusse - 2014-04-27

    Quoting the manual;

    When the option is used inside the options of a node, the parsing of the node stops
    immediately after the end of the option block

    When using node contents, node location requires at=<(coord or name)> syntax as an option. The following works;

        \begin{tikzpicture}
        \foreach \i in {1,2,3}{
        \node[node contents={a},at={(\i,0)}] ;
        }
        \end{tikzpicture}
    

    However, as far as I can see, there is no need to use node contents in this context if you would like to keep the at <(coord or name)> syntax on the path.

     
    • Ignasi

      Ignasi - 2014-04-28

      In fact I needed to specify node contents in .style declaration. I didn't know that at was also possible in node options.

      Issue solved from my point of view.

       
  • Christian Feuersänger

    • status: open --> closed-invalid
     
  • Christian Feuersänger

    Thanks for the comments. Closing issue accordingly.