Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When I use \subcaption{... \label{myfig}} in memoir, and then reference it, the result is something like "Figure 1(a)". But I would like to customize the reference by removing the parentheses, thus making it appear as "Figure 1a".

How do I do that in memoir? I can't find anything in the manual.

share|improve this question
1  
See daleif's comment to this question –  egreg Oct 18 '11 at 14:17
    
I see. That's annoying, but oh well, I'll have to live with it. Thanks. I suppose this question can be closed due to duplication (funny I didn't find that question when I did a search). –  gablin Oct 18 '11 at 15:08
2  
Perhaps we should merge here: the two sets of answers have useful information in, but really the question is the same. –  Joseph Wright Oct 18 '11 at 16:13
    
@JosephWright I think you're right, they should be merged. Why isn't there a "vote to merge" as well as "vote to close as exact duplicate" –  Seamus Jan 21 '12 at 11:35
    
@Seamus I think first the question has to be closed, and only then can it be merged –  Joseph Wright Jan 21 '12 at 12:22
add comment

2 Answers

up vote 6 down vote accepted

It is possible to do this using some string manipulation from the xstring package. Using a combination of \StrBefore and \StrBetween, the "parent" and subfigure numbers can be extracted and printed as in your requirement. However, this would require some more work if needed with hyperref.

Below is a new macro \subfigref{<label>} that should be used to obtain this output, where <label> is the reference label used in the subfigure caption. It should also work for other subfloats.

enter image description here

\documentclass{memoir}% http://ctan.org/pkg/memoir
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{xstring}% http://ctan.org/pkg/xstring
\usepackage{xspace}% http://ctan.org/pkg/xspace
\newsubfloat{figure}% Allow subfigures using \subbottom/\subtop
\newcommand*{\subfigref}[1]{\StrBefore{\ref{#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{This is a caption} \label{fig:label}
\end{figure}
See Figure~\ref{fig:label}. It has subfigures~\subfigref{fig:label:a} and~\subfigref{fig:label:b}.
\end{document}
share|improve this answer
add comment

Inspired by Werner's, here's a definition that works with hyperref

\documentclass{memoir}
\usepackage[demo]{graphicx}
\newsubfloat{figure}% Allow subfigures using \subbottom/\subtop

\usepackage{refcount}
\newcommand\sref[1]{\edef\next{\getrefnumber{#1}}%
  \begingroup\edef\x{\endgroup
    \noexpand\hyperref[#1]{\expandafter\stripparens\next()\nnil}}\x}

\def\stripparens#1(#2)#3\nnil{\if\relax\detokenize{#2}\relax??\else#1#2\fi}

\usepackage{hyperref}

\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{This is a caption} \label{fig:label}
\end{figure}
See Figure~\ref{fig:label}. It has subfigures~\sref{fig:label:a} and~\sref{fig:label:b}.

\end{document}

If hyperref is not loaded, then change the definition of \sref into

\newcommand\sref[1]{\edef\next{\getrefnumber{#1}}%
  \expandafter\stripparens\next()\nnil}

It's a kludge and requires \sref instead of \ref, but it seems to work. When memoir will be adapted so that the aspect of references to subfloats is customizable, it will be necessary only to say

\let\sref\ref
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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