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 want to use a variable that could be used in TikZ code to get an external data file, and outside this code to define a legend associated. TikZ won't let me use \caption inside its environment, and the label solution doesn't work...

For example with various external drawing I want to be able to use the name of the drawing in a caption pretty much like that:


\caption{drawing of \tex}

It sounds trivial to me but I couldn't find anything.

share|improve this question
What kind of variable is it? You should be able to use a \caption inside a \node. Please consider adding a minimal working example (MWE) that illustrates your problem. – Martin Scharrer Aug 4 '11 at 17:48
MWE is now done ! – ben paillard Aug 4 '11 at 18:01
up vote 1 down vote accepted

This appears to be a problem with scoping. If you move the \def to be before the tikzpicture things should work. Alternatively using a gdef (which makes the definition global) instead of \def, should also work.

share|improve this answer
worked indeed, thanks ! dunno why but I thought \def was something defined in tikz environment. – ben paillard Aug 4 '11 at 19:36

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.