tikzlibrary chains misbehaving

It is not a bug. To treat { ... } as a TikZ scope - as opposed to just an ordinary TeX group - you need to load the scopes library.

\documentclass[tikz,multi,border=10pt]{standalone}
\usetikzlibrary{chains,scopes}
\begin{document}
\begin{tikzpicture}[node distance=1mm,
  every node/.style=draw,every join/.style=->]
  \draw [help lines] (0,0) grid (3,2);
  \node[red] (existing) at (0,2) {existing};
  {[start chain]
    \node [draw,on chain,join] {Hello};
    \node [draw,on chain,join] {World};
    \chainin (existing) [join];
    \node [draw,on chain,join] {this};
    \node [draw,on chain,join] {is};
  }
\end{tikzpicture}
% last example from section on chains, page 542
\begin{tikzpicture}[node distance=5mm,
every node/.style=draw]
{ [start chain=1]
\node [on chain] {A};
\node [on chain] {B};
\node [on chain] {C};
}
{ [start chain=2 going below]
\node [on chain=2] at (0.5,-.5) {0};
\node [on chain=2] {1};
\node [on chain=2] {2};
}
{ [continue chain=1]
\node [on chain] {D};
}
\end{tikzpicture}
\end{document}

scopes

last example

One persistent issue with the PGF/TikZ manual is its tendency to assume that the correct libraries are loaded, even when example code uses libraries which were mentioned several pages earlier or which were mentioned only briefly, in passing or implicitly. This can make it difficult to use from a user's perspective. (And presumably the manual is supposed to serve us as users, so this is something of a short-coming.)

In this case, many, many of the examples for the chains library assume that at least scopes is loaded and it would be very helpful if this could be mentioned right at the beginning of the section, along with the syntax for loading the chains library itself.


A single brace is not a replacement for a proper TikZ scope which does quite a lot of nontrivial things.

Hence you need to spell out the \begin{scope} then everything works properly. Thus, I wouldn't call this a bug but a typo in the documentation.

\documentclass[tikz]{standalone}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[node distance=1mm,
every node/.style=draw,every join/.style=->]
\draw [help lines] (0,0) grid (3,2);
\node[red] (existing) at (0,2) {existing};
\begin{scope}[start chain,]
\node [draw,on chain,join] {Hello};
\node [draw,on chain,join] {World};
\chainin (existing) [join];
\node [draw,on chain,join] {this};
\node [draw,on chain,join] {is};
\end{scope}
\end{tikzpicture}
\end{document}

CFR and percusse both posted a much better solution to the code and provided a much better explanation for as to why the typo arose in the manual. One of them should be marked correct.

Original post:

You are correct in that it seems to be an error in the code. Simply moving the start chain into the optional part of \begin{tikzpicture} seems to correct this. This can be seen in the previous examples.

Also, in my copy of the manual, which I believe is the most recent one, the mentioned example is on page 545, not that it matters too much as you included the section number, which is a lot more useful.

A bug report has been filed just now, #392 Documentation, section 46.3, example produces error

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[start chain,node distance=1mm,
every node/.style=draw,every join/.style=->]
\draw [help lines] (0,0) grid (3,2);
\node[red] (existing) at (0,2) {existing};
{
\node [draw,on chain,join] {Hello};
\node [draw,on chain,join] {World};
\chainin (existing) [join];
\node [draw,on chain,join] {this};
\node [draw,on chain,join] {is};
}
\end{tikzpicture}
\end{document}

Tags:

Tikz Pgf