This can be similarly formulated to Why are just-created TikZ shapes "unknown"?; but its slightly different. Here is the MWE:



\begin{adjustbox}{width=1.0\textwidth}% fbox,
\tikzstyle{bb} = [draw,line width=1pt]
\tikzstyle{brdec} = [thick, decoration={ brace, mirror, amplitude=8pt, raise=8pt }, decorate]%
\tikzstyle{brdecn} = [pos=0.5,anchor=north,yshift=-1.5em]%

\foreach \a/\b in {
} {
  \typeout{1st loop; name is: bn\a};
  \node[bb] (bn\a) at (\a,0) {\b};

\foreach \a/\b/\c in {
} {
  \pgfmathtruncatemacro{\next}{\a+1} % returns int
  \typeout{2nd loop; name is: brz\c};
  \draw[brdec] (bn\a.south west) -- (bn\next.south east)
    node[brdecn] (brz\c) {\b};

\foreach \a/\b/\c in {
} {
  \pgfmathtruncatemacro{\next}{\a+1} % returns int
  \typeout{3rd loop; name is: brf\b};
  \draw[brdec] (brz\a.south west) -- (brz\next.south east)
    node[brdecn] (brf\b) {\c};


The output from pdflatex is this:

...ABD: EveryShipout initializing macros
1st loop; name is: bn0
1st loop; name is: bn1
1st loop; name is: bn2
1st loop; name is: bn3
1st loop; name is: bn4
1st loop; name is: bn5
1st loop; name is: bn6
1st loop; name is: bn7
2nd loop; name is: brz0
2nd loop; name is: brz1
2nd loop; name is: brz2
2nd loop; name is: brz3 
3rd loop; name is: brf0
3rd loop; name is: brf1

! Package pgf Error: No shape named brz3 is known.

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.

l.63 }

Note that brz3 should be, in fact, created (and the typeout shows that the problem is not floating point numbers, like in the solution for the question cited above) - and there are no problems referencing other nodes; in fact, if I instruct pdflatex to keep going after this error, I get this:


Does anyone have an idea what is going on, and how to solve this problem?

EDIT: Many thanks to @alexwlchan, however, if I add commas after the first two loops (7/t8, and 6/x4/3,), I get this:


Adding a comma to the third loop (2/1/z2,) adds an additional rotated brace. I think with an additional comma, tikz runs one more iteration of the loop, but with empty arguments, thereby resulting with the extra erroneous brace. Any way to fix this?


The problem comes at the end of the list of cases in your \foreach loops

\foreach \a/\b/\c in {

When it reads 6/x4/3, there’s no comma or closing brace afterwards, so it includes the whitespace in the definition of \c.

This means you get a node called brz3 (+ some other stuff). Somebody who understands TikZ better than me could tell you exactly what that is, but it isn’t important.

This means that when TikZ looks for a node called brz3, it doesn’t match the one you’ve created. You should add a trailing comma at the end of the list, and then it only reads the single character 3.

As sdaau has pointed out, this creates an empty entry in the loop and messes up the braces. Instead, you should bring the closing brace up, so that the entry for 3 is only a single character, and it finishes off the loop.

This matches the rest of your nodes, and the names match:

\foreach \a/\b/\c in {
  % some code here

You also need to add a trailing comma move the closing brace on the first loop which sets up your bn nodes, or you get a similar error, for the same reason.

  • Many thanks for the answer, @alexwlchan - the compilation now passes, but the output is wrong; please see edit to OP. Cheers! – sdaau Apr 17 '14 at 17:45
  • 1
    @sdaau: Try moving the final brace to remove the newline, rather than adding a trailing comma. I’ve edited to clarify. – alexwlchan Apr 17 '14 at 17:49
  • 2
    Many thanks for that, @alexwlchan - it works! Also just adding a comment at the end, e.g. 7/t8% worked for me (and then I can keep the end brace on its own line, too). Many thanks again - cheers! – sdaau Apr 17 '14 at 17:51
  • Or you can remove the spurrious space by appending a % to the last line. – jub0bs Apr 17 '14 at 18:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.