[Tex/LaTex] Is it possible to use hyperref, subfigure, and memoir together

hyperrefmemoirsubfloatswarnings

I asked a question about how to use subfigure with memoir. I got some great tips, but now pdflatex is making all subfigure hyper-refs point to the first couple subfigures. It also gives me this error:

destination with the same identifier (name{subfigure.3}) has been already used, duplicate ignored

for every subfigure (except the first one at any index, i.e., the first {subfigure.n} gets no error for every n.)

I was pointed to this, but hyperref is the last package loaded.

Has anyone gotten this working?


Solution:

Make sure that

\newsubfloat{figure}

follows

\usepackage{hyperref}

Best Answer

Please provide an example where it is not working? This seems to work for me:

\documentclass{memoir}

\usepackage{hyperref}
\newsubfloat{figure}

\begin{document}

\begin{figure}
  \centering
  \subtop[Sub~a.]{Foo\label{subfig:a}}\qquad
  \subtop[Sub~b.]{Bar\label{subfig:b}}
  \caption{First.}
\end{figure}

\clearpage

\begin{figure}
  \centering
  \subtop[Sub~c.]{Baz\label{subfig:c}}\qquad
  \subtop[Sub~d.]{Foobar\label{subfig:d}}
  \caption{Second.}
\end{figure}

\clearpage
\noindent
Main: \ref{subfig:a} Sub: \subcaptionref{subfig:a}\\
Main: \ref{subfig:b} Sub: \subcaptionref{subfig:b}\\
Main: \ref{subfig:c} Sub: \subcaptionref{subfig:c}\\
Main: \ref{subfig:d} Sub: \subcaptionref{subfig:d}

\end{document} 

You can even use the \autoref from hypreref if you like.

\documentclass{memoir}

\usepackage{hyperref}
\newsubfloat{figure}

\providecommand*{\subfigureautorefname}{Subfig.}

\begin{document}

\noindent
\autoref{fig:1} on page \pageref{fig:1} contains two subfigures, 
\autoref{subfig:a} \& \subcaptionref{subfig:b}.

\clearpage

\begin{figure}
  \centering
  \subtop[Sub~a.]{Foo\label{subfig:a}}\qquad
  \subtop[Sub~b.]{Bar\label{subfig:b}}
  \caption{First.}\label{fig:1}
\end{figure}

\end{document}
Related Question