[Tex/LaTex] Revtex 4.2 caption error

revtexsubcaptionsubfig

\documentclass[amssymb,aps,twocolumn,pra,nobibnotes,secnumarabic,prc]{revtex4-2}
\usepackage{tabularx}
\usepackage[labelformat=simple,caption=false]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}
\usepackage{graphicx
\usepackage{lineno}
\usepackage{dcolumn}   % needed for some tables
\usepackage{bm}
\usepackage{amsmath}   % for math
\usepackage{amssymb}
\usepackage{multirow}
\usepackage{csquotes}
\usepackage{commath}
\begin{document}
\begin{figure}[htb]
    \captionsetup[subfigure]{singlelinecheck=off}
    \begin{tabularx}{\linewidth}{*{3}{X}}
        \begin{subfigure}[b]{\linewidth}
            \label{subfig:a}
            \includegraphics[width=\linewidth]{figures/hydro2}
            \caption{}
        \end{subfigure}
        &
        \begin{subfigure}[b]{\linewidth}
            \caption{}\label{subfig:b}
            \includegraphics[width=\linewidth]{figures/hydro1}
        \end{subfigure}       
    \end{tabularx}
    \caption{jdjdkkd}
    \label{fig:a}
\end{figure}
\end{document}

And i get errors like:
Package caption Error: caption undefined. \end{tabularx}
Improper \prevdepth. \caption{jdjdkkd}

Best Answer

The caption package, hence subcaption as well, is not compatible with revtex4-2. You get

Package caption Warning: Unsupported document class (or package) detected,
(caption)                usage of the caption package is not recommended.
See the caption package documentation for explanation.

The error you get is due to caption=false, anyhow.

You can use subfig instead.

\documentclass[amssymb,aps,twocolumn,pra,nobibnotes,secnumarabic,prc]{revtex4-2}
\usepackage[caption=false]{subfig}
\usepackage{graphicx}
%\usepackage{commath} % Oh, no!

\usepackage{lipsum} % for context

\begin{document}

\lipsum[1]

\begin{figure}[htb]

\subfloat[\label{subfig:a}]{%
  \includegraphics[width=0.3\columnwidth]{example-image}%
}\hfill
\subfloat[\label{subfig:b}]{%
  \includegraphics[width=0.3\columnwidth]{example-image}%
}\hfill
\subfloat[\label{subfig:c}]{%
  \includegraphics[width=0.3\columnwidth]{example-image}%
}

\subfloat[\label{subfig:d}]{%
  \includegraphics[width=0.3\columnwidth]{example-image}%
}\hfill
\subfloat[\label{subfig:e}]{%
  \includegraphics[width=0.3\columnwidth]{example-image}%
}\hfill
\subfloat[\label{subfig:f}]{%
  \includegraphics[width=0.3\columnwidth]{example-image}%
}

\caption{jdjdkkd}\label{fig:a}

\end{figure}

\lipsum

\end{document}

There's no need for tabularx, just use a bit less than 1/3 of the line width (which is better called \columnwidth) and filler glue between images.

enter image description here

I'd recommend against using commath. See https://tex.stackexchange.com/a/123408/4427, https://tex.stackexchange.com/a/135985/4427 and https://tex.stackexchange.com/search?q=commath+user%3A4427

Related Question