2

I need to have subcaption labels (and references) be of the format

Fig. 1a

Instead of the default "(a)", and be able to reference them with \cref

Unfortunately, I can't seem to get any subcaption related commands change the format of the subcaption "label" (is that the correct name for this?)

This is as close as I can get (while still having \cref work for normal, non-subfigure figures).

As you can see, I'm using memoir. The problem with the below code is that the references using \cref start with the figure counter (the first "1" below), and I can't seem to get rid of it. I understand this is the wrong way to handle it (I change the counter to include a name/label instead of changing the caption format). Any proper solution is very welcome, failing that, a hack to fix my hack is welcome as well!

\documentclass{memoir}

\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}

\newsubfloat{figure}

\renewcommand{\thesubfigure}{Fig. \arabic{figure}\alph{subfigure}}
\renewcommand{\thefigure}{\arabic{figure}}

\crefformat{subfigure}{#2{}#1{}#3{}}

\begin{document}
\begin{figure}
\subbottom[first subfigure \label{fig:first}]{\fbox{Numero uno}}
\subbottom[second subfigure \label{fig:second}]{\fbox{Numero dos}}
\end{figure}
\cref{fig:first}

\cref{fig:second}
\end{document}

enter image description here

EDIT it seems also that if I don't use \caption the figure number isn't incremented and a following normal figure will use the same figure number. Is there an automated way to change this behaviour? Currently, I'm adding a \addtocounter{figure}{1} in each subfig only figure, which has the desired effect.

  • Isn't it simpler for you to use use say the subfig package instead? – daleif Nov 13 '15 at 10:19
  • @daleif I thought that package was deprecated. I also didn't find any way to do what I wanted there... – rubenvb Nov 13 '15 at 10:46
  • Where did you see that information? As far as I now it us the subfigure package that is no longer maintained. – daleif Nov 13 '15 at 10:51
  • @daleif my mistake. Still couldn't get as close as I am above with that package. – rubenvb Nov 13 '15 at 10:56
1

This is quit unusualrequest/demand ... here is one solution, but it probably will make a mess at normal use of figure referencing:

\documentclass{memoir}

\usepackage{hyperref}
\usepackage[[capitalise]{cleveref}

\newsubfloat{figure}
\renewcommand{\thesubfigure}{Fig.~\arabic{figure}\alph{subfigure}}

\crefformat{subfigure}{#2#1#3}
\begin{document}
\begin{figure}[h]\centering
     \renewcommand{\thefigure}{} 
\subbottom[first subfigure  \label{fig:1}]{\fbox{figure numero uno}}
    \hfil
\subbottom[second subfigure \label{fig:2}]{\fbox{figure numero dos}}
    \stepcounter{figure}
\end{figure}
    some text
\begin{figure}[h]\centering
     \renewcommand{\thefigure}{} 
\subbottom[first subfigure  \label{fig:3}]{\fbox{figure numero uno}}
    \hfil
\subbottom[second subfigure \label{fig:4}]{\fbox{figure numero dos}}
   \stepcounter{figure}
\end{figure}
some text
\begin{figure}[h]\centering
\fbox{some "normal" figure}
    \caption{normal figure}
    \label{fig:5}
\end{figure}

\cref{fig:1} and \cref{fig:4} and also \cref{fig:5}
    \end{document}

enter image description here

Edit: Desired look-out is achieved by use \renewcommand{\thefigure}{} in each float with subfigures and \stepcounter{figure} before end of figure float. Now I hope is fulfilled your requests.

  • There are also normal figures, so I can't mess up their label formatting. I understand the unusuality of the request, and believe me I don't agree with the result, but I was given a task to make a 1:1 copy of a badly formatted Word document. So I want to see how close I can get it! – rubenvb Nov 13 '15 at 12:30
  • Well, this can be partially fulfilled by moving \renewcommand{\thefigure}{} inside float, see edit of my answer. – Zarko Nov 13 '15 at 13:21

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.