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.

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

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
up vote 6 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
I am trying to accomplish practically the same thing, only within a groupplot. Though the manual says that the groupplot environment should function basically the same as the axis environment, it doesn't seem to with regard to names. So where you used name=plt so that you could later use \node[at=(plt.south) I can't seem to replicate for a groupplot. No matter what I try, I get the error No shape named plt is known. – jerH May 17 '15 at 21:58

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.