3

Is there a way to configure the style of references to memoir's built-in subfloats, i.e. when using \subcaptionref, and \ref? For example, is it possible to remove the parentheses?

From the memoir documentation:

Figure \ref{fig:twosubfig} has two subfigures,
  namely \ref{sf:1}, \subcaptionref{sf:2}.

\begin{figure}
\centering
\subbottom[Subfigure 1]{\fbox{SUBFIGURE ONE}\label{sf:1}}
\hfill
\subbottom[Subfigure 2]{\fbox{SUBFIGURE TWO}\label{sf:2}}
\caption{Figure with two subfigures} \label{fig:twosubfig}
\end{figure}

produces

Figure 10.19 has two subfigures, namely 10.19(a), (b).

Can this be changed to e.g.

Figure 10.19 has two subfigures, namely 10.19a, b.

To be clear, the changes should preferably only apply to the reference, not the subcaption itself.

  • 3
    I have found an answer in the related questions here, which says that the parentheses are hardwired as of 2011. Is this still the case? – user90893 Oct 28 '15 at 12:26
  • 1
    It is, it is on my todo list, but not with high priority. You might want to consider the subfig package or similar – daleif Oct 28 '15 at 12:29
  • @daleif Thanks for the quick response, if you put this into an answer I'll accept it straight away. As for using another package, it's not important enough for that. – user90893 Oct 28 '15 at 12:45
  • It is not a real answer for the question, – daleif Oct 28 '15 at 12:57
  • Possible duplicate of Adding parentheses around subfig references – Zarko Oct 28 '15 at 13:26
1

The following updates the way subcaption references are written to the .aux, making \subcaptionref pull the appropriate non-parenthesized reference:

enter image description here

\documentclass{memoir}

\usepackage{etoolbox}

\newsubfloat{figure}
\newcommand{\thesubfigureref}{\alph{subfigure}}
\makeatletter
\AtBeginDocument{
  \patchcmd{\sf@@memsub@label}% <cmd>
    {\@nameuse{@@thesub\@captype}}% <search>
    {\@nameuse{thesub\@captype ref}}% <replace>
    {}{}% <success><failure>
}
\makeatother

\begin{document}

\setcounter{chapter}{9}% Just for this example
\chapter{A chapter}
\setcounter{figure}{18}% Just for this example

Figure \ref{fig:twosubfig} has two subfigures,
  namely \ref{fig:twosubfig}\subcaptionref{sf:1}, \subcaptionref{sf:2}.

\begin{figure}[ht]
  \centering
  \subbottom[Subfigure 1]{\fbox{SUBFIGURE ONE}\label{sf:1}}
  \subbottom[Subfigure 2]{\fbox{SUBFIGURE TWO}\label{sf:2}}
  \caption{Figure with two subfigures} \label{fig:twosubfig}
\end{figure}

\end{document}

Changes are required if you're loading the hyperref package (or nameref package) as well.

  • If I parse this correctly, the @@thesub<type> command is responsible for printing the reference, and is by default defined as thesub<type>, which contains the parentheses. Would it therefore not suffice to simply redefine \@namedef{@@thesubfigure}{\alph{subfigure}} globally and get the references as I want them for plain, nameref and hyperref all at once? – user90893 Oct 28 '15 at 17:12
  • Or actually just \def\@@thesubfigure{\alph{subfigure}} as I don't think \@namedef does anything else in this case. – user90893 Oct 28 '15 at 17:21
  • @user5254: Yes, that's a good option. Add \makeatletter \def\@@thesubfigure{\alph{subfigure}} \makeatother after \begin{document}. – Werner Oct 28 '15 at 18:13
1

From Werner's answer and a bit of digging through memoir.cls, it follows that it is much easier to change the subfigure counter to the desired style, e.g. no parentheses, and afterwards fix the subcaption label using the \@thesubfigure macro.

changed subfigure reference style

\documentclass[oneside]{memoir}

% works with and without hyperref
%\usepackage{hyperref}

% create a figure subfloat
\newsubfloat{figure}

% change style
\makeatletter
\def\thesubfigure{\alph{subfigure}}
\def\@thesubfigure{(\alph{subfigure})%
            \if@tightsubcap\hskip\subfloatlabelskip\else\space\fi}
\makeatother

\begin{document}

Figure \ref{fig:twosubfig} has two subfigures,
  namely \ref{sf:1}, \subcaptionref{sf:2}.

\begin{figure}[h]
\centering
\subbottom[Subfigure 1]{\fbox{SUBFIGURE ONE}\label{sf:1}}
\hfill
\subbottom[Subfigure 2]{\fbox{SUBFIGURE TWO}\label{sf:2}}
\caption{Figure with two subfigures} \label{fig:twosubfig}
\end{figure}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy