\tableofcontents 给出未定义的控制序列错误

\tableofcontents 给出未定义的控制序列错误

论坛,

我正在使用 overleaf 上的 LaTeX 模板撰写我的论文。通常,生成目录只是\tableofcontents文档中某处的事情。但是,当我尝试这样做时,LaTeX 给出了以下编译错误:

l.24 \tableofcontents
                     
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

有人知道这是怎么回事吗?我该如何解决这个问题?我也检查过了\listoffigures\listoftables它们也抛出了类似的错误。

我知道这里的错误必须完全可重现。但由于模板包含一个.cls+- 2000 行的文件,我决定不在这里粘贴所有内容。重现问题最简单、最快的方法是打开此模板位于背面\tableofcontents并在第 24 行中添加main.tex。任何帮助都将不胜感激。

答案1

问题在于文件中未定义 \tableofcontents 功能.cls。在 .cls 文件的第 530 行,\newcommand{\contentsname}{Contents}添加以下代码片段:

\newcommand{\tableofcontents}{
  \section*{\contentsname}
  \@starttoc{toc}
}

这解决了问题。

相关内容