3

I am writing a document using the memoir class. I would like to create a figure with two subfigures and to display a caption like "Plot of Y vs X with z=1 (a) and with z=2 (b)", where "(a)" and "(b)" are references to the subfigures.

I read How to reference subfigure in caption and Customize referencing of subcaptions in “memoir”?. The following example based on Werner's code solve my problem.

\documentclass{memoir}
\newsubfloat{figure}
\usepackage[demo]{graphicx}
\usepackage{xstring}
\usepackage{xspace}

\newcommand*{\subfigref}[1]{(\StrBetween{\ref{#1}}{(}{)})\xspace}%

\begin{document}

\begin{figure}[ht]
\centering
\subbottom[This is a subfigure\label{fig:label:a}]{\includegraphics{figure1}} \qquad
\subbottom[This is a subfigure\label{fig:label:b}]{\includegraphics{figure2}}
\caption{These are some awesome figures: \protect\subfigref{fig:label:a} and \protect\subfigref{fig:label:b} }
\label{fig:label1}
\end{figure}

\end{document}

How can I make the previous example work with hyperref ? In Customize referencing of subcaptions in “memoir”?, egreg seems to know how to do this but I do not understand enough his answer to use it for this particular problem.

EDIT

Note that I would also like to keep references such as "in Figure 0.1(a)" outside the figure.

1 Answers1

2

You can redefine \p@subfigure which controls the prefix that will be added to the subfigure counter:

\documentclass{memoir}
\newsubfloat{figure}
\usepackage[demo]{graphicx}
\usepackage{hyperref}

\makeatletter
\renewcommand\p@subfigure{}
\makeatother

\begin{document}

\begin{figure}[ht]
\centering
\subbottom[This is a subfigure\label{fig:label:a}]{\includegraphics{figure1}} \qquad
\subbottom[This is a subfigure\label{fig:label:b}]{\includegraphics{figure2}}
\caption{These are some awesome figures:~\protect\ref{fig:label:a} and~\protect\ref{fig:label:b} }
\label{fig:label1}
\end{figure}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128
  • Thank you for your help. Unfortunately, if I use \ref{fig:label:a} outside the figure, it will appear as "(a)" and I would like it like "0.1(a)". Using \begingroup changes nothing. I edited my question to make this point clearer. – Raphaël Coudret Mar 27 '13 at 08:03
  • @Ragnaroob ah, I see. Then my answer is no longer valid; perhaps I will keep it for reference. – Gonzalo Medina Mar 27 '13 at 14:45
  • @RaphaëlCoudret perhaps \subcaptionref could be helpful. C.f., https://tex.stackexchange.com/a/115093/37198 – davyjones Oct 07 '18 at 09:43