19

I used to have code like this: \caption{In \subref{fig:foo:a} you can see...}. Now I switched to using memoirs subtop/subbottom command instead of \subfigure. How can I refer to that subfigure?

As a temporary step I changed \subref to \autoref but that results in output like "In 1.1a you can see... ", I want "In (a) you can see...".

  • tex.stackexchange.com/questions/30572/… might be relevant – jonalv Oct 17 '11 at 13:59
  • I saw that but I specifically only want the non-number part. I.e. the letter (a, b) – Unapiedra Oct 17 '11 at 14:03
  • 2
    It is always best to compose a MWE that illustrates the problem including the \documentclass so that those trying to help don't have to recreate it. – Peter Grill Oct 17 '11 at 15:32
6

memoir defines a "parent" macro for each of the subfloat counters. More specifically, when you issue the command

\newsubfloat{figure}% Allow for subfigures

it creates the subfigure counter as well as a p@subfigure macro to extract/prints the parent figure number. Modifying this macro to be empty removes this functionality. If you only want to disable this "parent" counter removal temporarily, you should use grouping to limit the scope of the macro redefinition:

enter image description here

\documentclass{memoir}
\usepackage[margin=10mm]{geometry}% http://ctan.org/pkg/geometry
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
% Allow subfloats for the following floats via \subbottom and/or \subtop
\newsubfloat{figure} % Subfigures
\newsubfloat{table} % Subtables
\begin{document}
\begingroup
\makeatletter
\renewcommand{\p@subfigure}{}% Void parent macro for figures
\makeatother
\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}
  \label{fig:label1}
\end{figure}
See Figure~\ref{fig:label1}. It has subfigures~\ref{fig:label:a} and~\ref{fig:label:b}.
\endgroup

\begin{figure}[ht]
  \centering
  \subbottom[This is a subfigure\label{fig:label:c}]{\includegraphics{figure3}} \qquad
  \subbottom[This is a subfigure\label{fig:label:d}]{\includegraphics{figure4}}
  \caption{These are some awesome figures}
  \label{fig:label2}
\end{figure}
See Figure~\ref{fig:label2}. It has subfigures~\ref{fig:label:c} and~\ref{fig:label:d}.

\begin{table}[ht]
  \centering
  \subbottom[This is a subtable\label{tbl:label:a}]{\includegraphics{table1}} \qquad
  \subbottom[This is a subtable\label{tbl:label:b}]{\includegraphics{table2}}
  \caption{These are some awesome tables}
  \label{tbl:label}
\end{table}
See Table~\ref{tbl:label}. It has subtables~\ref{tbl:label:a} and~\ref{tbl:label:b}.
\end{document}

geometry was loaded just to make the minimal example fit on a single page.

| improve this answer | |
  • Thanks! Also learned about the \begingroup command. – Unapiedra Oct 18 '11 at 16:36
10

I don't know if this is a new addition but as documented in the manual, on page 206, you can achieve this with \subcaptionref. Here is an example adapted from the manual:

\documentclass{memoir} 

\newsubfloat{figure} % Subfigures

\begin{document}

Figure \ref{fig:twosubfig} has two subfigures, namely \ref{sf:1} and \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}

\end{document}

Output:

Correct subfigure referencing

| improve this answer | |
  • 1
    Great suggestion! That solves my problem in a more elegant way than the other solutions proposed here. Thanks a lot! – rmbianchi Sep 29 '15 at 16:59
2

One solution is to type that in by hand. This isn't an idiomatic solution and quite evident that it isn't great. It is easy to make a mistake (i.e. if subfigures are moved around).

However, it is not completely bad because the scope of usage will always be local. I will use this in the caption of the figure itself and from there reference the subfigures. It would be different if I were to do this in the body.

See this answer as the challenge to provide a better answer.

| improve this answer | |
-1

Change subfigure.sty...

...
\DeclareOption{figbotcap}{\figuretopcapfalse}

\DeclareOption{figtopcap}{\figuretopcaptrue}

...

change for:

...

\DeclareOption{figbotcap}{\figuretopcaptrue}

\DeclareOption{figtopcap}{\figuretopcapfalse}

...
| improve this answer | |
  • 4
    Welcome to TeX.SX. Usually it is better to not edit directly originals .sty files. There are always other options for doing the same job. – Claudio Fiandrino Dec 27 '13 at 18:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.