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.

  • 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
    Commented Dec 7, 2012 at 19:10
  • 1
    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
    Commented Dec 7, 2012 at 19:31
  • Just wait a little bit(!) and the system will allow you to answer your own question.
    – percusse
    Commented Dec 7, 2012 at 19:35

1 Answer 1


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.

  • 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? Commented Dec 8, 2012 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
    Commented May 17, 2015 at 21:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .