# How to make sub figure referencing work in memoir + cleveref?

In the following example:

\documentclass{memoir}
\usepackage{cleveref}
\newsubfloat{figure}
\begin{document}

\chapter{Example}
\begin{figure}
\centering
\subtop[apple]{fig 100a\label{fig:100a}}\\
\subtop[orange]{fig 100b\label{fig:100b}}
\caption{Can you handle subfigures?}
\label{fig:100}
\end{figure}

\cref{fig:100a} and \namecref{fig:100b}.
\Cref{fig:100}
\end{document}


Both \cref{fig:100a} and \namecref{fig:100b} produce ??

The versions of packages used are: cleveref.sty 0.17.2 and memoir.cls v3.6.

-

You should contact Toby Cubitt, the author of cleveref. He is very responsive to bug reports and the memoir support of cleveref is very new and little tested.

The problem is that memoir redefines \label within subfigures, so the cleveref version does not get used...

In the meantime, it's not pretty, but this works for your example at least:

\documentclass{memoir}
\usepackage{cleveref}
\crefname{subfigure}{fig.}{figs.}
\Crefname{subfigure}{Figure}{Figures}

\newsubfloat{figure}
\begin{document}

\makeatletter
\let\old@sf@@memsub@label=\sf@@memsub@label
\renewcommand*{\sf@@memsub@label}[1]{%
\@bsphack%
\old@sf@@memsub@label{#1}%
\protected@write\@auxout{}%
{\string\newlabel{cref@#1}{{\cref@currentlabel}{\thepage}}}%
\@esphack}
\makeatother

\chapter{Example}
\begin{figure}
\centering
\subtop[apple]{fig 100a\label{fig:100a}}\\
\subtop[orange]{fig 100b\label{fig:100b}}
\caption{Can you handle subfigures?}
\label{fig:100}
\end{figure}

\cref{fig:100a} and \namecref{fig:100a}.
\Cref{fig:100}
\end{document}

-
Thanks for this. My current workaround is to load subfig instead. –  Leo Liu Aug 8 '10 at 19:07
Has this problem been fixed in memoir and/or cleveref? I'm running into the same problem and considering that this issue first came up 1.5 years ago, I'm wondering whether I don't need to find a workaround. Nut –  user1362373 Feb 21 '12 at 17:41
According to the changelog in the manual this should be fixed in v0.18.5 which is currently only available at Tony's own site. –  Jonas Nyrup Mar 18 '12 at 16:59