4

I have the following problem: if I use package \usepackage{subcaption} to construct subfigures, my caption under the figure* becomes not justified. To demonstrate this problem I use "RevTeX 4.2 Template and Sample" from Overleaf:

\documentclass[amsmath,amssymb, aps]{revtex4-2}

\usepackage{graphicx}% Include figure files

\usepackage{dcolumn}% Align table columns on decimal point

\usepackage{bm}% bold math

\usepackage[format=plain, justification=justified]{subcaption}

. . .

\begin{figure*}

\includegraphics{fig_2}\caption{...Long not justified caption...}

\end{figure*}

. . .

The Result 1:

enter image description here

The caption is justified, if I do not use \usepackage{subcaption}. Here is the Result 2:

enter image description here

I want my caption to be as in Result 2 but with included \usepackage{subcaption}. I would be happy to get any help! Thank You in advance!

1
  • revtex and caption don't go along. But you can use \usepackage[caption=false]{subfig} (it has a different syntax), so revtex caption are not touched.
    – egreg
    Jun 30, 2020 at 15:26

2 Answers 2

3

You get a warning

Package caption Warning: Unknown document class (or package),
(caption)                standard defaults will be used.
See the caption package documentation for explanation.

This means that caption will revert the caption commands to something it knows which is definitely not what revtex4-2 expects.

Following John Kormylo's advice, but adding \show\caption (for debugging) after \begin{document} issues

> \caption=macro:
->\minipagefootnote@here \caption@iftype {\caption@checkgrouplevel \@empty \cap
tion \caption@star {\caption@refstepcounter \@captype }{\caption@dblarg {\@capt
ion \@captype }}}{\caption@Error {\noexpand \caption outside float}\caption@gob
ble }.

whereas the original definition of the class is

> \caption=macro:
->\minipagefootnote@here \ifx \@captype \@undefined \@latex@error {\noexpand \c
aption outside float}\@ehd \expandafter \@gobble \else \refstepcounter \@captyp
e \expandafter \@firstofone \fi {\@dblarg {\@caption \@captype }}.

So it's not just a question of saving and restoring \@makecaption.

If you want to live dangerously and risk your submission is rejected…

Otherwise, use subfig, which is compatible with revtex4-2.

\documentclass[amsmath,amssymb, aps]{revtex4-2}
\usepackage{graphicx}% Include figure files
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}% bold math
\usepackage[caption=false]{subfig}

\begin{document}

\begin{figure*}
\subfloat[A subcaption\label{A}]{\includegraphics[width=2cm]{example-image-a}}\quad
\subfloat[A subcaption\label{B}]{\includegraphics[width=2cm]{example-image-a}}

\bigskip

\includegraphics[width=5cm]{example-image}
\caption{...Long not justified caption...
...Long not justified caption...
...Long not justified caption...
...Long not justified caption...
...Long not justified caption...
...Long not justified caption...
...Long not justified caption...
...Long not justified caption...
...Long not justified caption...\label{C}}
\end{figure*}

\ref{A}, \ref{B}, \ref{C}

\end{document}

enter image description here

1
  • Dear egreg, Thank you very much! Everything works fine! Jul 6, 2020 at 13:24
1

This restores the original \@makecaption. This also disables any formatting applied by the caption or subcaption packages.

\documentclass[amsmath,amssymb, aps]{revtex4-2}
\usepackage{graphicx}% Include figure files
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}% bold math
\makeatletter
\let\old@makecaption=\@makecaption
\usepackage{subcaption}
\let\@makecaption=\old@makecaption
\makeatother
\usepackage{blindtext}

\begin{document}
\begin{figure*}
\includegraphics{example-image}
\caption{\blindtext}% justified
\subcaption{\blindtext}% centered
\end{figure*}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .