[Tex/LaTex] Editing the reference style for subfigures using cleveref and memoir

cleverefcross-referencingmemoirsubfloats

I'm using the cleveref package to reference floats (in this case subfigures) in the memoir class. Currently the output looks like this (sorry for the danish, I don't think it matters):
subfigures in memoir using cleveref

Using the following input (not all packages included, ofc):

\documentclass[oneside,article,12pt,danish]{memoir}
\usepackage{graphicx}
\newsubfloat{figure}
\captiontitlefont{\slshape}
\subcaptionfont{\slshape}

\usepackage{varioref}
\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}

\begin{figure}[h!]
  \centering
  \subbottom[Subfigure 1 caption]{\rule{3cm}{1cm}\label{sub1}}
  \hspace{1cm}
  \subbottom[Subfigure 2 caption]{\rule{3cm}{1cm}\label{sub2}}
\caption{Figure text.}
\label{fig:secondfig}
\end{figure}

\cref{sub1,sub2}

\end{document}

I like the way the figure/subfigures are set up, but I would like the reference to say 5a or 5.a instead of 5(a) without changing the figure/subfigure captions. Is there a general way to do this in the entire document, so that it can be easilly be changed to a somewhat random notation?

Best Answer

This solution avoids the need to load caption and thereby retains the facilities of memoir. At least, it seems so although my testing has been somewhat minimal. Uncomment/comment the appropriate line to achieve formatting with or without the dot, as the mood takes you.

\documentclass[oneside,article,12pt,danish]{memoir}
\newsubfloat{figure}
\captiontitlefont{\slshape}
\subcaptionfont{\slshape}

% \renewcommand{\thesubfigure}{\alph{subfigure}}% plain version
\renewcommand{\thesubfigure}{.\alph{subfigure}}% dotted version
\makeatletter
\renewcommand{\@thesubfigure}{(\alph{subfigure})%
    \if@tightsubcap\hskip\subfloatlabelskip\else\space\fi}
\makeatother

\usepackage{varioref}
\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}

\begin{figure}[h!]
  \centering
  \subbottom[Subfigure 1 caption]{\rule{3cm}{1cm}\label{sub1}}
  \hspace{1cm}
  \subbottom[Subfigure 2 caption]{\rule{3cm}{1cm}\label{sub2}}
\caption{Figure text.}
\label{fig:secondfig}
\end{figure}

\cref{sub1,sub2}

\end{document}

sub figures with variant referencing format in <code>memoir</code>

Were you to load xcolor then you could (perversely) have just the references to the sub-figure bits typeset in huge, blue lowercase without affecting the captions or other references:

\renewcommand{\thesubfigure}{\Huge\color{blue}.\alph{subfigure}}% dotted version

bizarre formatting

Obviously, this would be a terrible choice but it demonstrates that the format can be easily 'changed to a somewhat random notation' while retaining the format of sub-captions and the interface of memoir.

Related Question