I try to create Tikz figure with several pgfplots subplots. I want to have one legend for them since they all have the same curves. I found out from this question that i can label and than reference each curve. I used that to create simple legend at the bottom of the subplots. And it looked just fine when I tried it as a separate file. Then I put it in my thesis where I use the Tikz external library which solves the TeX memory problem I encountered before because I have many plots. The problem that occurs can be reproduced by this MWE:

\addplot coordinates { (0,0) (1,1) };\label{plot:p1}
\node (A) at (1,-1) {\ref{plot:p1} Plot 1};

which produces:

enter image description here

instead of:

enter image description here

(I'm using just one plot here instead of subplots for simplicity). Notice the question marks for the missing reference in the first image. Of course, if I comment out the 4th line (don't use externalize) the reference turns out just fine (the second image). So I wonder:

How can I get the reference and still use externalize?

P.S.: TexLive 2011 on Ubuntu 11.10


1 Answer 1


As Ignasi said in the comment, this doesn't work completely automatically.

From the pgfplots manual:

There is just a special case if a \label/\ref drawn as a tikzpicture. This is, for example, the case for the legend \ref images or for the \pgfplotslegendfromname feature. In such cases, you need to proceed as for case a) since mode=convert with system call can't handle that stuff on its own.

Case a) suggests to

consider using mode=list and make or copy{paste the system call for the image(s) and issue it manually.

Your example works for me if I add

    /tikz/external/mode=list and make

to the file and run make -B -f <filename>.makefile after the first compile run.

  • 1
    Important: you may need to deliver the .dpth files along with the .pdf for every figure. See also here. (I don't actually know if it applies to this case, but it may.)
    – Raphael
    Jun 1, 2015 at 14:37

You must log in to answer this question.

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