[Tex/LaTex] Undefined control sequence caption

captionserrorssubcaption

When I compile document that has such code:

\usepackage{caption}
\usepackage{subcaption}
\DeclareCaptionLabelSeparator{emdash}{~--- }
\captionsetup[figure]{labelsep=emdash,font=onehalfspacing,position=bottom}
\captionsetup{%
    singlelinecheck=off,
    skip=2pt,
    justification=centering,
}

% ...

\begin{figure}[h]
    \centering
    \includegraphics[width=0.8\textwidth]{test.png}
    \caption{Text here}
\end{figure}

I get error line 54: Undefined control sequence. \caption{Text here}.
How to resolve this issue?

P.S. Without caption all works properly.

Best Answer

Most likely the error is labelsep=emdash.

Either the declaration has been forgotten or it's easy to define emdash:

\DeclareCaptionLabelSeparator{emdash}{\textemdash}
\documentclass{article}


\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{setspace}


\DeclareCaptionLabelSeparator{emdash}{\textemdash}
\captionsetup[figure]{labelsep=emdash,font=onehalfspacing,position=bottom}
\captionsetup{%
  singlelinecheck=off,
  skip=2pt,
  justification=centering,
}


\begin{document}

\begin{figure}[h]
    \centering
    \includegraphics[width=0.8\textwidth]{ente}
    \caption{Text here}
\end{figure}

\end{document}

enter image description here

Related Question