1

I'm trying to understand a particular error encountered from using a subfloat within a figure. A MWE to reproduce the error:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\subfloat[][A]{\includegraphics[width=0.5\textwidth]{example-image-a}\label{fig:1a}}
\subfloat[\label{fig:1b}][B]{\includegraphics[width=0.5\textwidth]{example-image-b}}
\caption[abc]{abcdefg}\label{fig:stuff}
\end{figure}

\end{document}

produces the message:

./mwe.tex:11: Undefined control sequence.
<argument> ...sub\@captype }}}{\caption@subreffmt 
                                                  {\@nameuse {p@sub\@captype...
l.11 ...textwidth]{example-image-a}\label{fig:1a}}
                                                  
? 

If I move the label for the subfloat A within the first [] (as done for subfloat B), the example compiles. Removing subcaption from the MWE also removes the error without further changes to the MWE, so it's unclear to me if this might be a bug in subcaption, or a convention that I'm not understanding in how the subfloat labels are supposed to be placed.

0

1 Answer 1

2

Don't load the package subfig together with subcaption. Actually, since subcaption loads caption, the line

\usepackage{subcaption}

is sufficient.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}

\begin{figure}
\centering
\subfloat[][A]{\includegraphics[width=0.5\textwidth]{example-image-a}\label{fig:1a}}
\subfloat[\label{fig:1b}][B]{\includegraphics[width=0.5\textwidth]{example-image-b}}
\caption[abc]{abcdefg}\label{fig:stuff}
\end{figure}

\end{document}

You must log in to answer this question.

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