cleveref 中缺少图号

cleveref 中缺少图号

使用 cleveref 时,子标题引用中缺少图号。如何获取子标题引用作为图 1(a),而不是图 (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}

在此处输入图片描述

答案1

您的示例文档可以归结为:

\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}

这里发生了什么:该figureSeries包用于\DeclareCaptionSubType*将图形计数器作为子图形计数器的一部分。并且\renewcommand\thesubfigure{(\alph{subfigure})}您删除了子图形标签的图形部分,但\labelresp.\ref不知道您的重新定义(因此不会在图形计数器前面添加图形计数器,因为它假定它已经是子图形计数器的一部分),结果您完全消除了图形部分。

可以采取的措施是:如果您不喜欢该包的子图设置figureSeries,请使用(不带星号)反转此设置\DeclareCaptionSubType,例如:

\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}

相关内容