TransWikia.com

cleveref: "Fig" for citing multiple subfigures from the same figure, but "Figs" when citing multiple subfigures from different figures

TeX - LaTeX Asked by FranciscoD on August 17, 2021

For one of our journal submissions, the editorial office has sent us the following remark:

The singular "Fig" should be used when citing panels of the same
figure, e.g. "Fig 3A and 3B" or "Fig 3A, 3B, 3C and 3D". The plural
"Figs" should be used when the panels belong to different figures e.g.
"Figs 3A and 4B", or "Figs 3A, 4B, 5C, and 5D".

We’re using cleveref in the document, and the "panels" in the figures are different subfigures. This is what we’re currently using to set up cleveref:

usepackage[capitalise]{cleveref}
crefformat{figure}{#2Fig~#1#3}
Crefformat{figure}{#2Fig~#1#3}
crefmultiformat{figure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{figure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}

Whatever is specified in the last two commands ("Fig" or "Figs") applies to all lists of subfigures, irrespective of whether they are from the same figure or not. Would someone know if it is possible to implement the convention required by the publishers? I did look at the cleveref documentation but couldn’t figure out if this could be done simply by updating the cleveref configuration above.

Here’s the MWE:

documentclass{article}

usepackage{csquotes}
usepackage[aboveskip=1pt,labelfont=bf,labelsep=period,justification=raggedright,singlelinecheck=off]{caption}
renewcommand{figurename}{Fig}
usepackage{subcaption}
renewcommand{thesubfigure}{Alph{subfigure}}
captionsetup[subfigure]{labelfont={sf,bf},labelsep=space,labelformat=simple,margin=-15pt,skip=-10pt,position=top}
captionsetup[figure]{skip=5pt,labelfont={bf},position=bottom}
usepackage[capitalise]{cleveref}
crefformat{figure}{#2Fig~#1#3}
Crefformat{figure}{#2Fig~#1#3}
crefmultiformat{figure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{figure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
usepackage{graphicx}
usepackage{mwe}


begin{document}
begin{figure}[!t]
  centering
  begin{subfigure}[c]{0.53textwidth}
    subcaption{}label{fig:1a}%
    includegraphics[width=textwidth]{example-image}% Image from the mwe package
    end{subfigure}quad%
    begin{subfigure}[c]{0.40textwidth}
      subcaption{}label{fig:1b}%
      includegraphics[width=textwidth]{example-image}% Image from the mwe package
      end{subfigure}
      caption{Test figure 1}label{fig:1}
end{figure}

begin{figure}[!t]
  centering
  begin{subfigure}[c]{0.53textwidth}
    subcaption{}label{fig:2a}
    includegraphics[width=textwidth]{example-image}% Image from the mwe package
    end{subfigure}quad%
    begin{subfigure}[c]{0.40textwidth}
      subcaption{}label{fig:2b}%
      includegraphics[width=textwidth]{example-image}% Image from the mwe package
      end{subfigure}vspace{0.2cm}
      caption{Test figure 2}label{fig:2}
end{figure}
Cref{fig:1a,fig:1b} or cref{fig:2a,fig:2b} should say enquote{Fig} but cref{fig:1a,fig:1b,fig:2a,fig:2b} should use enquote{Figs}.

end{document}

and here’s the output:

enter image description here

One Answer

You can resort to defining two languages, English, as the default, and another (I choose Dutch), and then change the caption by selecting the secondary language.

b

Add to the preamble

%% ***************************************** added
usepackage[dutch, english]{babel}
makeatletter
addtocaptionsdutch{%
crefmultiformat{subfigure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{subfigure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
}
addtocaptionsenglish{%
crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
}
makeatother    

newcommand{crefx}[1]{% <<<<<<<<
    selectlanguage{dutch}%
        cref{#1}%
    selectlanguage{english}% 
}
%% ***************************************** added

and use the command crefx

This is the complete code.

documentclass{article}

usepackage{csquotes}
usepackage[aboveskip=1pt,labelfont=bf,labelsep=period,justification=raggedright,singlelinecheck=off]{caption}
renewcommand{figurename}{Fig}
usepackage{subcaption}
renewcommand{thesubfigure}{Alph{subfigure}}
captionsetup[subfigure]{labelfont={sf,bf},labelsep=space,labelformat=simple,margin=-15pt,skip=-10pt,position=top}
captionsetup[figure]{skip=5pt,labelfont={bf},position=bottom}

usepackage[capitalise, english]{cleveref}% <<<<<<<<<<<<<<

crefformat{figure}{#2Fig~#1#3}
Crefformat{figure}{#2Fig~#1#3}
crefmultiformat{figure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{figure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}

usepackage{graphicx}
usepackage{mwe}

%% ***************************************** added
usepackage[dutch, english]{babel}
makeatletter
addtocaptionsdutch{%
crefmultiformat{subfigure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{subfigure}{Figs~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
}
addtocaptionsenglish{%
crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
Crefmultiformat{subfigure}{Fig~#2#1#3}{ and~#2#1#3}{, #2#1#3}{, and~#2#1#3}
}
makeatother    

newcommand{crefx}[1]{% <<<<<<<<
    selectlanguage{dutch}%
        cref{#1}%
    selectlanguage{english}% 
}
%% ***************************************** added

begin{document}
begin{figure}[!t]
    centering
    begin{subfigure}[c]{0.53textwidth}
        subcaption{}label{fig:1a}%
        includegraphics[width=textwidth]{example-image}% Image from the mwe package
    end{subfigure}quad%
    begin{subfigure}[c]{0.40textwidth}
        subcaption{}label{fig:1b}%
        includegraphics[width=textwidth]{example-image}% Image from the mwe package
    end{subfigure}
    caption{Test figure 1}label{fig:1}
end{figure}

begin{figure}[!t]
    centering
    begin{subfigure}[c]{0.53textwidth}
        subcaption{}label{fig:2a}
        includegraphics[width=textwidth]{example-image}% Image from the mwe package
    end{subfigure}quad%
    begin{subfigure}[c]{0.40textwidth}
        subcaption{}label{fig:2b}%
        includegraphics[width=textwidth]{example-image}% Image from the mwe package
    end{subfigure}vspace{0.2cm}
    caption{Test figure 2}label{fig:2}
end{figure}

Cref{fig:1a,fig:1b} or cref{fig:2a,fig:2b} should say enquote{Fig}       

crefx{fig:1a,fig:1b,fig:2a,fig:2b} should use enquote{Figs}. % <<<<<<<<<<<<<< changed     

But not enquote{Fig} like in  cref{fig:1a,fig:1b,fig:2a,fig:2b}       
    
end{document}

NOTE cleveref needs to be tell the default language when using babel:

usepackage[capitalise, english]{cleveref}%

Correct answer by Simon Dispa on August 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP