当涉及 \ContinuedFloat 时从 \ref 收到错误输出

当涉及 \ContinuedFloat 时从 \ref 收到错误输出

我在标题中获得了以下形式的自定义编号方案:

  • 图 A.1.5

  • “5”是章节计数器,

  • “1”是数字计数器,

  • 而“A”是的计数器ContinuedFloat

     \documentclass[12pt]{book}
     \usepackage[colorlinks]{hyperref}
     \usepackage{cleveref}
     \usepackage{graphicx}
    
     \usepackage{caption}
    
     \captionsetup[figure]{labelsep=period,font=small,labelfont=small}
    
     \renewcommand\thefigure{\arabic{figure}.\thechapter}  
    
     \renewcommand\theContinuedFloat{\Alph{ContinuedFloat}.}
    
     \DeclareCaptionLabelFormat{MyFormat}{#1 \theContinuedFloat \arabic{figure}.\thechapter}
     \captionsetup[ContinuedFloat]{labelformat=MyFormat}
    
    
     \begin{document}
     \setcounter{chapter}{4}
     \chapter{Chapter five}
     \section{Section one}
     \begin{figure}[!ht]
     \ContinuedFloat*
     \centering
     \includegraphics[scale=.25]{example-image}
     \caption{This is my caption}
     \label{fig:A:1:5}
     \end{figure}
    
     \begin{figure}[!ht]
     \ContinuedFloat
     \centering
     \includegraphics[scale=.25]{example-image}
     \caption{This is my caption}
     \label{fig:B:1:5}
     \end{figure}
    
     we have in \ref{fig:A:1:5} that \ref{fig:B:1:5}
     \end{document}
    

在此处输入图片描述

当我通过 命令引用相同内容时\ref,奇怪地得到的是“1.5A.”而不是“A.1.5”。

我不想使用subcaption包裹。

答案1

包装手册caption指出(重点是我的):

如果你也想使用 ContinuedFloat 计数器来引用,你可以重新定义命令 \theContinuedFloat,它将是附加到图形或表格自动计数器处于连续浮动状态并且预设为空。

因此,为了引用目的,在计数器的末尾附加了 ContinuedFloat 计数器,即添加到计数器末尾,从而导致了1.5A.您注意到的行为。

您可以通过重新定义实现此行为的包中的命令来更改此设置caption。您可以将 ContinuedFloat 计数器放在开头,而不是放在末尾,这样引用格式将与您自己的 CaptionLabelFormat 相匹配。源代码位于caption.sty代码的大约 1/3 处。在下面的 MWE 中,导致问题的行被注释掉,并在其下方添加了一个新行来实现反向顺序。

梅威瑟:

\documentclass[12pt]{book}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref}
\usepackage{graphicx}

\usepackage{caption}
\makeatletter
\renewcommand*\caption@@@@continuedfloat[1]{%
  \caption@setoptions{ContinuedFloat}% for compatibility reasons
  \caption@setoptions{continuedfloat}%
  \caption@setoptions{continued#1}%
  %\expandafter\l@addto@macro\csname the#1\endcsname\thecontinuedfloat
  \expandafter\def\csname the#1\endcsname{\Alph{ContinuedFloat}.\arabic{#1}.\thechapter}
  \@ifundefined{theH#1}{}{%
    \expandafter\l@addto@macro\csname theH#1\endcsname{%
      \@alph\c@continuedfloat}}%
  \let\caption@@@@continuedfloat\@gobble}
\makeatother
\captionsetup[figure]{labelsep=period,font=small,labelfont=small}

\renewcommand\thefigure{\arabic{figure}.\thechapter}  

\renewcommand\theContinuedFloat{\Alph{ContinuedFloat}.}

\DeclareCaptionLabelFormat{MyFormat}{#1 \theContinuedFloat \arabic{figure}.\thechapter}
\captionsetup[ContinuedFloat]{labelformat=MyFormat}


\begin{document}
\setcounter{chapter}{4}
\chapter{Chapter five}
\section{Section one}
\begin{figure}[!ht]
\ContinuedFloat*
\centering
\includegraphics[scale=.25]{example-image}
\caption{This is my caption}
\label{fig:A:1:5}
\end{figure}

\begin{figure}[!ht]
\ContinuedFloat
\centering
\includegraphics[scale=.25]{example-image}
\caption{This is my caption}
\label{fig:B:1:5}
\end{figure}

\begin{figure}[!ht]
\centering\fbox{non-continued figure}
\caption{some figure}
\label{somefig}
\end{figure}

we have in \ref{fig:A:1:5} that \ref{fig:B:1:5}

regular figure: \ref{somefig}
\end{document}

结果:

在此处输入图片描述

答案2

答案代码取自 Marijn,但经过修改,因此仅caption使用该包的记录功能。这个没有重新定义\theContinuedFloat,而是声明了一个选项来修改\thefigure连续浮点数:

\documentclass[12pt]{book}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref}
\usepackage{graphicx}

\usepackage{caption}
\captionsetup[figure]{labelsep=period,font=small,labelfont=small}

\renewcommand\thefigure{\arabic{figure}.\thechapter}

\DeclareCaptionOption{continuedfigure}
  {\renewcommand\thefigure{\Alph{ContinuedFloat}.\arabic{figure}.\thechapter}}
\captionsetup[ContinuedFloat]{continuedfigure=}

\begin{document}
\setcounter{chapter}{4}
\chapter{Chapter five}
\section{Section one}
\begin{figure}[!ht]
\ContinuedFloat*
\centering
\includegraphics[scale=.25]{example-image}
\caption{This is my caption}
\label{fig:A:1:5}
\end{figure}

\begin{figure}[!ht]
\ContinuedFloat
\centering
\includegraphics[scale=.25]{example-image}
\caption{This is my caption}
\label{fig:B:1:5}
\end{figure}

\begin{figure}[!ht]
\centering\fbox{non-continued figure}
\caption{some figure}
\label{somefig}
\end{figure}

we have in \ref{fig:A:1:5} that \ref{fig:B:1:5}

regular figure: \ref{somefig}
\end{document}

顺便说一句:如果\thefigure通过这种方式修改,就不需要自己的自定义标签格式,所以我放弃了\DeclareCaptionLabelFormat{myformat}{...}

答案3

或者,也可以进行修改\label以存储除 之外的其他内容\thefigure

 \documentclass[12pt]{book}
 \usepackage[colorlinks]{hyperref}
 \usepackage{cleveref}
 \usepackage{graphicx}

 \usepackage{caption}

 \captionsetup[figure]{font=small,labelfont=small}

 \renewcommand\thefigure{\arabic{figure}.\thechapter}  

 \DeclareCaptionLabelFormat{MyFormat}{#1 \Alph{ContinuedFloat}.\thefigure}
 \captionsetup[ContinuedFloat]{labelformat=MyFormat}

\makeatletter
\newcommand{\mylabel}{\edef\@currentlabel{\Alph{ContinuedFloat}.\thefigure}\label}
\makeatother

 \begin{document}
 \setcounter{chapter}{4}
 \chapter{Chapter five}
 \section{Section one}
 \begin{figure}[!ht]
 \ContinuedFloat*
 \centering
 \includegraphics[scale=.25]{example-image}
 \caption{This is my caption}
 \mylabel{fig:A:1:5}
 
 \end{figure}

 \begin{figure}[!ht]
 \ContinuedFloat
 \centering
 \includegraphics[scale=.25]{example-image}
 \caption{This is my caption}
 \mylabel{fig:B:1:5}
 \end{figure}

 we have in \ref{fig:A:1:5} that \ref{fig:B:1:5}
 \end{document}

相关内容