6

When I use Hyperref package together with memoir class, and when I put a label to a PGFPlot inside a subbottom environment, and try to reference to it, an error reported:

! File ended while scanning use of \Hy@setref@link.

A MWE:

\documentclass[11pt, letterpaper, oneside, article]{memoir}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usepackage[hyperfootnotes=true]{hyperref}
\newsubfloat{figure}

\begin{document}
A test for hyperref, subbottom of memoir class, and legend reference.
This is the legend reference:\ref{plot:firstplot}.

\begin{figure}[hbt]
\centering
\subbottom[]{
\begin{tikzpicture}
\begin{axis}
  \addplot coordinates {(0,0)(0.5,1)(1,2)};
  \label{plot:firstplot}
\end{axis}
\end{tikzpicture}
}
\end{figure}

\end{document}

If we do not use Hyperref, or if we do not put the plot inside subbottom, things would work out well.

strpeter
  • 5,215
J. Li
  • 61
  • 1

1 Answers1

6

I can reproduce the issue.

The cause is that both memoir and pgfplots override \label (in an incompatible way). Pgfplots has some workaround to restore its own \label locally, but that work-around appears to conflict with some operation caused by hyperref.

A workaround is to load hyperref before pgfplots, in this case, everything works as expected.

I would prefer a better solution which works in all cases, but it may need a deep digging into the root cause (volunteers?).