TeX - LaTeX Asked by Qaher on June 9, 2021
I get my custom numbering scheme in captions in the following form:
Figure A.1.5
the "5" is the chapter counter,
the "1" is the figure counter,
and the "A" is the counter for the ContinuedFloat
.
documentclass[12pt]{book}
usepackage[colorlinks]{hyperref}
usepackage{cleveref}
usepackage{graphicx}
usepackage{caption}
captionsetup[figure]{labelsep=period,font=small,labelfont=small}
renewcommandthefigure{arabic{figure}.thechapter}
renewcommandtheContinuedFloat{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}
When I reference the same ones through the command of ref
, I weirdly get "1.5A." instead of "A.1.5".
I don’t want to use subcaption
package.
The manual of the caption
package states that (emphasis mine):
If you would like to use the ContinuedFloat counter for the references, too, you could redefine the command theContinuedFloat instead, which will be appended to the figure or table counter automatically in continued floats and is preset to be empty.
So, the ContinuedFloat counter is appended, i.e., added at the end, of the counter for referencing purposes, resulting in the 1.5A.
behavior that you have noticed.
You can change this by redefining the command in the caption
package that implements this behavior. Instead of putting the ContinuedFloat counter at the end you can put it at the beginning, so the reference format will match your own CaptionLabelFormat. The source is found in caption.sty
at about 1/3 of the code. In the MWE below the line causing the issue is commented out and a new line is added below that to implement the reverse order.
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}%
%expandafterl@addto@macrocsname the#1endcsnamethecontinuedfloat
expandafterdefcsname the#1endcsname{Alph{ContinuedFloat}.arabic{#1}.thechapter}
@ifundefined{theH#1}{}{%
expandafterl@addto@macrocsname theH#1endcsname{%
@alphc@continuedfloat}}%
letcaption@@@@continuedfloat@gobble}
makeatother
captionsetup[figure]{labelsep=period,font=small,labelfont=small}
renewcommandthefigure{arabic{figure}.thechapter}
renewcommandtheContinuedFloat{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]
centeringfbox{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}
Result:
Correct answer by Marijn on June 9, 2021
Alternatively, one can modify label
to store something other than thefigure
.
documentclass[12pt]{book}
usepackage[colorlinks]{hyperref}
usepackage{cleveref}
usepackage{graphicx}
usepackage{caption}
captionsetup[figure]{font=small,labelfont=small}
renewcommandthefigure{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}
Answered by John Kormylo on June 9, 2021
Answer code taken from Marijn but modified so only documented features of the caption
package are used. This one does not redefine theContinuedFloat
but declares an option instead to modify thefigure
for continued floats:
documentclass[12pt]{book}
usepackage[colorlinks]{hyperref}
usepackage{cleveref}
usepackage{graphicx}
usepackage{caption}
captionsetup[figure]{labelsep=period,font=small,labelfont=small}
renewcommandthefigure{arabic{figure}.thechapter}
DeclareCaptionOption{continuedfigure}
{renewcommandthefigure{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]
centeringfbox{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}
BTW: If thefigure
is modified this way there is no need for an own custom label format, so I dropped the DeclareCaptionLabelFormat{myformat}{...}
.
Answered by user205700 on June 9, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP