0

I want to use cleveref to reference to panels inside a figure. Thereby I design the entire figure outside LaTeX with labels a, b, ... for the different panels. To this end I need some dummy subfigures with labels. So what I did was:

\documentclass[prl,twocolumn]{revtex4-2}

\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{cleveref}

\begin{document}
\maketitle

See \cref{fig:1:a}

\begin{figure}
    \begin{subfigure}{\textwidth} % this 'subfigure' env. has no visible content
        \refstepcounter{subfigure}\label{fig:1:a}
        \refstepcounter{subfigure}\label{fig:1:b}
    \end{subfigure}%
    \centering
    \includegraphics[width=.5\textwidth]{example-image}
    \caption{(a) First sub caption. (b) Second sub caption. And some more text}
    \label{fig:1}
\end{figure}

\end{document}

Which gives (zoom):

enter image description here

The problem is however that subcaption changes the formatting of the caption. For completeness, without the subfigure and without including subcaption the caption looked like this (zoom):

enter image description here

Since I do not use the subcaptions for anythings else then a dummy label I do not want to change the formatting of the my caption at all.

So my question is simple: How do I get dummy subcaption labels without the subcaption package?

2 Answers 2

1

Option (1) Use \captionsetup[figure]{...} to get back the right format.

d

    \documentclass[prl,twocolumn]{revtex4-2}

\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{cleveref}

\captionsetup[figure]{textfont=normalfont,singlelinecheck=off,justification=raggedright}% added <<<

\usepackage{kantlipsum}
\begin{document}
    \maketitle
    
    See \cref{fig:1a}
    
    \begin{figure}[ht]
        \begin{subfigure}{\textwidth} % this 'subfigure' env. has no visible content
            \refstepcounter{subfigure}\label{fig:1a}
            \refstepcounter{subfigure}\label{fig:1b}
        \end{subfigure}%
        \centering
        \includegraphics[width=\linewidth]{example-image}% use linewidth <<<
        %\caption{(a) First sub caption. (b) Second sub caption. And some more text}
            \caption{ (\protect\subref{fig:1a}) First sub caption.  (\protect\subref{fig:1b}) Second sub caption. And some more text}
        \label{fig:1}
    \end{figure}

    \kant[1-7]
\end{document}

or (2) Instead of subcaption it can be used subfig. (See the use of \subref{..} in the example)

c

\documentclass[prl,twocolumn]{revtex4-2}

\usepackage{graphicx}
\usepackage{subfig}
\usepackage{caption}
\usepackage{cleveref}

\usepackage{kantlipsum}

\captionsetup[figure]{textfont=normalfont,singlelinecheck=off,justification=raggedright}

\begin{document}
    \maketitle
    
    See \cref{fig:1a} and  subfigure~\subref{fig:1b}.   
    \begin{figure}[ht!]
        \subfloat{\label{fig:1a}}
        \subfloat{\label{fig:1b}}
        \centering
        \includegraphics[width=\linewidth]{FigureOne.pdf}
        \caption{ \protect\subref{fig:1a} First sub caption.  \protect\subref{fig:1b} Second sub caption. And some more text}
       \label{fig:1}
    \end{figure}
    
    \kant[1-7]
\end{document}

The FigureOne.pdf was generated by this file.

%%file FigureOne.tex

\documentclass[preview, border=5pt]{standalone}
\usepackage{geometry}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
    
    \begin{figure}
    \centering
    \subfloat[][]{\includegraphics[width=0.5\textwidth]{example-image-a}}\enspace
    \subfloat[][]{\includegraphics[width=0.5\textwidth]{example-image-b}}
\end{figure}    
\end{document}
3
  • Thanks a lot for the solutions. I like solution 2 because it simplifies the dummy labels a lot. However... neither are a solution of the problem ;). Using subfig, like subcaption, modifies the captionsetup, which in this answer is then re-modified by hand. The problem is that it does not correspond to the style given by the cls. Mostly though, an elegant solution would be to have a solution that simply does not touch the captionsetup at all. Sep 1, 2021 at 7:52
  • @Tom de Geus Customizing the caption style for figures and table is standard practice after loading the package caption. In the same way we specify the dimensions of the page after loading geometry. After all, it is unreasonable for the default settings coincide or automatically adjust to our wishes. Sep 1, 2021 at 13:24
  • I can very much agree to it. However, I am looking to respect a prescribed style and not looking to approximate it afterwards. So my question is not so much to get a 'fix' (or work-around), but to elegantly solve this problem no matter if I change the cls with specifies a different style. Sep 1, 2021 at 13:57
0

Answers (2) by @Simon Dispa suggests using the subfig package. It turns out that it has the option:

\usepackage[caption=false]{subfig}

According to the manual this is what I need:

For compatibility with other packages which modify the caption and where the stan- dard caption package whould interfere with the desired layout, the caption package has a special option, caption=false, which loads the internals (i.e., the "kernel" caption3 package) without modifying the \caption command.

Indeed, in a real example:

\documentclass[prl,twocolumn]{revtex4-2}

\usepackage{graphicx}
\usepackage[caption=false]{subfig}
\usepackage{cleveref}

\usepackage{kantlipsum}

\begin{document}
    \maketitle

    See \cref{fig:1a} and  subfigure~\subref{fig:1b}.
    \begin{figure}[ht!]
        \subfloat{\label{fig:1a}}
        \subfloat{\label{fig:1b}}
        \centering
        \includegraphics[width=\linewidth]{example-image}
        \caption{
            \protect\subref{fig:1a} First sub caption.
            \protect\subref{fig:1b} Second sub caption.
            \kant[8]}
       \label{fig:1}
    \end{figure}

    \kant[1-7]
\end{document}

the results looks like what I would expect: enter image description here

Indeed, without subfig the formatting is the same: enter image description here

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.