There are some issues when using the pgfplots option legend to name together with externalization. When I disable externalization, everything works fine. When I enable externalization, I get an error
! Undefined control sequence.
l.1 ...every legend to name picture/.try]\pgfplots@legend@to@name
and my document wont compile. Without the legend to name option, externalization works fine on the other hand. I am using version 1.5 of pgfplots according to \pgfplotsversion. A short example follows.
\documentclass{report}
% begin of externalization
\usepackage{pgfplots}
\usetikzlibrary{external}
\usepgfplotslibrary{external}
\tikzset{external/force remake}
\tikzexternalize
% end of externalization
\begin{document}
% example from manual, page 166
\pgfplotsset{footnotesize,samples=10}
\begin{center}% note that \centering uses less vspace...
\begin{tikzpicture}
\begin{axis}[
legend columns=-1,
legend entries={$(x+0)^k$;,$(x+1)^k$;,$(x+2)^k$;,$(x+3)^k$},
legend to name=named, % critical line
title={$k=1$}]
\addplot {x};
\addplot {x+1};
\addplot {x+2};
\addplot {x+3};
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[title={$k=2$}]
\addplot {x^2};
\addplot {(x+1)^2};
\addplot {(x+2)^2};
\addplot {(x+3)^2};
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[title={$k=3$}]
\addplot {x^3};
\addplot {(x+1)^3};
\addplot {(x+2)^3};
\addplot {(x+3)^3};
\end{axis}
\end{tikzpicture}
\\
\ref{named}
\end{center}
% end of example
\end{document}
Am I missing something?
\tikzexternaldisable\ref{named}\tikzexternalenableinstead of\ref{named}. – Hendrik Dec 07 '11 at 16:45First possibility:
Instead of
– Hendrik Dec 07 '11 at 17:09\cref{legendlabel}, always write\tikzexternaldisable\ref{legendlabel}\tikzexternalenable.Use a preamble
\pgfplotsset{invoke before crossref tikzpicture={\tikzexternaldisable},invoke after crossref tikzpicture={\tikzexternalenable}}and then reference legends normally with\cref{legendlabel}. It might be possible that this second possibility also prevents other pictures from being externalized, I have not tested this out.Source of this answer: Forum.
– Hendrik Dec 07 '11 at 17:09\creffor me, just\ref, weird – SpmP Feb 03 '15 at 03:10