未定义控制序列标题

未定义控制序列标题

当我编译包含此类代码的文档时:

\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}

我收到错误line 54: Undefined control sequence. \caption{Text here}。如何解决这个问题?

PS 没有标题一切正常。

答案1

最有可能的错误是labelsep=emdash

要么是声明被遗忘了,要么是很容易定义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}

在此处输入图片描述

相关内容