TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I understand that named elements of a tikzpicture cannot be referenced before they are defined; but I'm confused about how "long" a named element persists. It appears that once named, an element continues to exist, even in (subsequent) pictures that do not contain the element.

For example, the code


generates the expected "undefined element" error if used prior to the definition of 'e' and 'r', but once I create a picture containing code that defines these elements, subsequent figures containing exactly the code above will no longer produce an error, and will instead draw the requested arrow, between the locations in that figure corresponding to the locations of 'e' and 'r' in the original figure in which they were defined:

enter image description here

What is the default scope of tikzpicture element names? Is there a way to control their scope? The (apparent) default behavior seems likely to produce hard to debug behavior in figures.




    bluearrow/.style={->, blue, fill=none,>=stealth', thick},
    state/.style={circle,draw=black,inner sep=0pt,minimum size=7mm,label=center:$#1$,name=#1}}


% This fails here ...

\foreach \n\lab in \nodes{

\vspace{10 mm}

% ... but it works fine here.


share|improve this question
up vote 9 down vote accepted

TikZ itself adds a lot of internal groups, e.g. every \path ...; command is a TeX group. Because \node is basically just \path node the node name can not be defined locally because it would not survive it's own definition scope! While there are some techniques getting a macro out of a scope using such for every node (which is defined as a set of several macro) at every group inside a tikzpicture is just not doable. Therefore nodes etc. are defined globally, which makes them accessible for the rest of the document, even in other tikzpictures. The position of the node relative to the current origin should still be valid, so you could define \coordinate (my offset) at (1,1); in one tikzpicture and still use it in other ones. If you however want to draw directly to the original coordinate/node then remember picture,overlay is required.

share|improve this answer
Though I worry about debugging, I suppose (and can imagine) that there are scenarios in which this could be very useful. – raxacoricofallapatorius May 21 '12 at 20:27
No \node is not just \path [node]; node is a path operation and the definition is \path... node ... without [..]. It's not exactly a path operation like to , arc etc.. because the node is not exactly a part of a path but an object placed along a path. – Alain Matthes May 21 '12 at 20:50
But I agree with the big part of your answer – Alain Matthes May 21 '12 at 20:54
@Altermundus: Thanks, I corrected that. I confused \path [node] and \path node. – Martin Scharrer May 21 '12 at 21:19
When you say 'If you however want to draw directly to the original coordinate/node than remember picture,overlay is required.', you mean '... THEN remember picture...', right? – rvf0068 May 21 '12 at 23:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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