Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\documentclass{article}
\usepackage{tikz,graphicx}
\begin{document}

\begin{tikzpicture}
    \def\tex{texsx}
    \includegraphics[width=2cm]{\tex};
\end{tikzpicture}
\caption{drawing of \tex}
\end{document}

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.