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.

The following MWE without TikZ externalization works. However, the legend at the bottom is lost with externalization. Since the \ref in this example does not refer to anything outside tikzpicture environment, I thought this should work. However, I understand that latex needs to loop twice to resolve the reference and is not able to do it here.


      legend entries={$\sin(x)$},
      legend to name = named,
      name = plt 
    \addplot {sin(deg(x))}; 
  \node[at=(plt.south),anchor=north] {\ref{named}};

If I move \ref{named} outside the tikzpicture environment, I can generate two separate PDF files using list and make mode. However, I would like to keep the legends with my plot.

PS: MWE is only representative. This will be used for legend entries with multiple subplots.

share|improve this question
Did you try exhausting all the options stated in the manual? There is a whole section about how and why specifically adressing cross references.. –  percusse Dec 7 '12 at 19:10
Could you add answer with \pgfplotslegendfromname{name} instead of \ref{name}? I figured it out, but didn't know how to let people know. –  devendra Dec 7 '12 at 19:31
Just wait a little bit(!) and the system will allow you to answer your own question. –  percusse Dec 7 '12 at 19:35

1 Answer 1

up vote 3 down vote accepted

I figured out the solution. \ref is not really required in this case. If \ref{named} is substituted with \pgfplotslegendfromname{named} then the MWE works. Though \ref can be used to put the legend, it is not a good usage.

share|improve this answer
The failure of \ref sounds more like a bug to me... but good to know that there is a working solution. perhaps the externalization has to be run twice just a other latex documents? –  Christian Feuersänger Dec 8 '12 at 9:25

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.