[Tex/LaTex] Hyperref: destination with the same identifier (…) has been already used, duplicate ignored

hyperrefwarnings

From the MWE:

\documentclass{memoir} 

\usepackage{graphicx}
\newsubfloat{figure}
\usepackage{hyperref}

\begin{document}

\begin{figure}[h]
    \subbottom[Image A]{\includegraphics[width=0.5\columnwidth]{example-image-a}}
\end{figure}

\begin{figure}
    \subbottom[Image B]{\includegraphics[width=0.5\columnwidth]{example-image-b}}
\end{figure}

\end{document}

I get the warning destination with the same identifier (name{subfigure.1}) has been already used, duplicate ignored. If the [h] or the \usepackage{hyperref} is removed, the warning disappears.

  • Why do I get this warning?
  • How is it best resolved?
  • And what are the implications of continuing with this warning?

(I get several of these warnings in my non-MWE document, and I still want to link to the subfigures including page numbers using cleveref and varioref.)

Best Answer

Package hyperref needs to be loaded before \newsubfloat. The macro calls \@addtoreset, which is supported and patched by hyperref to fix the anchor name issue. But if the macro is called before, then the original version of \@addtoreset is called without the patch, and the anchor names would have to be fixed manually. But this is not necessary with the right order:

\documentclass{memoir}

\usepackage{graphicx}
\usepackage{hyperref}
\newsubfloat{figure}

\begin{document}

\begin{figure}[h]
  \subbottom[Image A]{\includegraphics[width=0.5\columnwidth]{example-image-a}}
  \caption{First}
\end{figure}

\begin{figure}
  \subbottom[Image B]{\includegraphics[width=0.5\columnwidth]{example-image-b}}
  \caption{Second}
\end{figure}

\end{document}