0

Figure number is missing in subcaption references, when using cleveref. How can I get a subcaption reference as Fig.1(a), instead of Fig. (a)?

\documentclass[12pt]{extarticle}
\RequirePackage{figureSeries}
\usepackage{algorithm}
\usepackage[colorlinks,citecolor=blue,urlcolor=blue,bookmarks=false,hypertexnames=true]{hyperref}
\usepackage[nameinlink,noabbrev,capitalise]{cleveref}
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}
\Crefname{figure}{Fig.}{Figs.}
\newcommand{\csubfloat}[2][]{\makebox[0pt]{\subfloat[#1]{#2}}}


% % packages for this example
\usepackage{mwe}
\usepackage{xcolor}


\begin{document}


\begin{figure}[H]
      \centering
      % Subfigure A
         \hspace*{\fill}%
            \csubfloat[First subcaption.]
            {\label{fig:Figure1a}%
            \includegraphics[width=5cm]{example-image-a}}
         \hspace*{\fill}
      % Subfigure B
         \hspace*{\fill}
            \csubfloat[Second subcaption.]
            {\label{fig:Figure1b}%
            \includegraphics[width=5cm]{example-image-b}}
         \hspace*{\fill}
      % Overall caption and label
         \caption{Overall caption of the Figure.}
         \label{fig:Figure1}
\end{figure}

Current reference to Figure 1a typesets as \textbf{\cref{fig:Figure1a}}.
\\
Current reference to Figure 1b typesets as \textbf{\cref{fig:Figure1b}}. 
\\ \\
\textbf{Why don't I get something like this?} {\color{red}\textbf{Fig.1(a)}} \textbf{and} {\color{red} \textbf{Fig.1(b)}} 


\end{document}

enter image description here

3
  • Do you know the subcaption package? I think you should give it a try, because it allows you to set/get references of subfigures (and subtables).
    – Venez
    Oct 29, 2020 at 16:23
  • Thanks a lot! Yes, as @P.M. just wrote, the \usepackage{subcaption} was part of the solution :)
    – user227870
    Oct 29, 2020 at 16:41
  • \usepackage{subcaption} is part of the figureSeries package. The solution is to revert the settings change of the figureSeries package with \DeclareCaptionSubType{figure}.
    – user205700
    Oct 29, 2020 at 16:42

1 Answer 1

1

Your example document could be boiled down to:

\documentclass[12pt]{article}

% from figureSeries.sty
% (taken from https://github.com/thomasWeise/figureSeries)
\usepackage{subcaption}
\DeclareCaptionSubType*[arabic]{figure}

% from your document
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}

\begin{document}
\begin{figure}[!ht]
\subfloat[Test\label{fig:1a}]{This is not an image}
\caption{Some text\ldots}
\end{figure}
\ref{fig:1a} % typesets "(a)"
\end{document}

What happens here: The figureSeries package uses \DeclareCaptionSubType* to make the figure counter part of the sub-figure counter. And with \renewcommand\thesubfigure{(\alph{subfigure})} you remove the figure-part of the sub-figure labeling, but \label resp. \ref is not aware of your re-definition (and therefore does not prepend the figure counter since it assumes that it is already part of the sub-figure counter), and as result you have eliminated the figure-part completely.

What could be done instead: If you don't like the sub-figure setup of the figureSeries package, reverse this setting with \DeclareCaptionSubType (without star), for example:

\documentclass[12pt]{article}

% from figureSeries.sty
\usepackage{subcaption}
\DeclareCaptionSubType*[arabic]{figure}

% from your document
\DeclareCaptionSubType{figure} % revert setting of figureSeries.sty
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple}
\renewcommand\thesubfigure{(\alph{subfigure})}

\begin{document}
\begin{figure}[!ht]
\subfloat[Test\label{fig:1a}]{This is not an image}
\caption{Some text\ldots}
\end{figure}
\ref{fig:1a} % typesets "1(a)"
\end{document}
3
  • Thanks a lot for the explanation and for the solution!!! I think I got confused with the figureSeries package...! I Just commented % \RequirePackage{figureSeries} and I added \usepackage{subcaption} \DeclareCaptionSubType{figure}
    – user227870
    Oct 29, 2020 at 16:38
  • If you don't use the figureSeries package anymore the line \DeclareCaptionSubType{figure} could be dropped since this is the default setting. (But it does not make any harm, so you could keep it, too.)
    – user205700
    Oct 29, 2020 at 16:44
  • Thanks a lot, I should study the packages more carefully!
    – user227870
    Oct 29, 2020 at 16:45

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.