1

I am using memoir and the sup-float support it provides. Here is a MWE (made by Werner originally in a different context, thanks):

\documentclass{memoir}
\usepackage{graphicx}
\newsubfloat{figure}% Allow subfloats in figure environment
\begin{document}

\begin{figure}
  \centering
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-a}\label{fig1}}
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-b}\label{fig2}}
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-c}\label{fig3}}
  \caption{Round}
\end{figure}

Figures \ref{fig1}-\ref{fig3} and \ref{fig2}-\ref{fig3}
\end{document}

In this examples the figures are referenced as Figures 0.1(a)-0.1(c) and 0.1(b)-0.1(c), however, I'd like for them to be referenced as Figures 0.1(a-c) and 0.1(b-c).

Is there a way to achieve this with memoir?

Werner
  • 603,163
BillyJean
  • 1,743

1 Answers1

1

Here is a fairly elementary implementation that tries to extract the subcaption "number" from \subcaptionref, assuming the default parenthesis enumeration is used.

enter image description here

\documentclass{memoir}

\usepackage{graphicx}
\newsubfloat{figure}% Allow subfloats in figure environment

\let\oldsubcaptionref\subcaptionref
\makeatletter
\@ifpackageloaded{hyperref}
  {\gdef\@firstof@{\@firstoffive}}
  {\gdef\@firstof@{\@firstoftwo}}

\renewcommand{\subcaptionref}{\@ifstar\subcaptionref@\subcaptionref@@}
\newcommand{\subcaptionref@}[1]{%
  \ifcsname r@sub@#1\endcsname
    \begingroup
    \edef\x{\csname r@sub@#1\endcsname}% Retrieve entire reference
    \edef\x{\expandafter\@firstof@\x}% Retrieve subfig reference
    \expandafter\strip@paren\x% Strip surrounding parenthesis (#1)
    \endgroup
  \else
    \textbf{??}%
  \fi
}
\newcommand{\subcaptionref@@}[1]{\oldsubcaptionref{#1}}
\def\strip@paren(#1){#1}% (#1) > #1
\makeatother

\begin{document}

\begin{figure}
  \centering
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-a}\label{fig1}}
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-b}\label{fig2}}
  \subbottom[Increase]{%
    \includegraphics[width=0.3\linewidth]{example-image-c}\label{fig3}}
  \caption{Round}\label{fig}
\end{figure}

Figures \ref{fig1}-\ref{fig3} and \ref{fig2}-\ref{fig3}.

Figures \ref{fig}(\subcaptionref*{fig1}-\subcaptionref*{fig3}) and \ref{fig}(\subcaptionref*{fig2}-\subcaptionref*{fig3}).

\end{document}

Note how each component is individually referenced as well as using the newly-defined starred version of \subcaptionref for extracting the sub-caption number.

Werner
  • 603,163