居中命令在目录之外工作正常;但在目录内部则完全不同

居中命令在目录之外工作正常;但在目录内部则完全不同

考虑一下代码

\documentclass[openany]{book}

\begin{document}
\thispagestyle{empty}
{\centering\Large\bfseries HERE IS A LONG SENTENCE THAT WILL NOT FIT ON ONE LINE, AND SO IT WILL BE DISPLAYED ON MORE THAN ONE LINE, ALL OF WHICH I WOULD LIKE TO CENTER.\par}

%\tableofcontents
%\addtocontents{toc}{{\centering\Large\bfseries HERE IS A LONG SENTENCE THAT WILL NOT FIT ON ONE LINE, AND SO IT WILL BE DISPLAYED ON MORE THAN ONE LINE, ALL OF WHICH I WOULD LIKE TO CENTER.\par}} 
\end{document}]

产生输出

在此处输入图片描述

没问题!

但是,当我采用相同的居中代码并将其插入到addtocontents命令中时,运行以下命令

\documentclass[openany]{book}

\begin{document}
\thispagestyle{empty}
{\centering\Large\bfseries HERE IS A LONG SENTENCE THAT WILL NOT FIT ON ONE LINE, AND SO IT WILL BE DISPLAYED ON MORE THAN ONE LINE, ALL OF WHICH I WOULD LIKE TO CENTER.\par}

\tableofcontents
\addtocontents{toc}{{\centering\Large\bfseries HERE IS A LONG SENTENCE THAT WILL NOT FIT ON ONE LINE, AND SO IT WILL BE DISPLAYED ON MORE THAN ONE LINE, ALL OF WHICH I WOULD LIKE TO CENTER.\par}} 
\end{document}]

我收到以下错误显示:

在此处输入图片描述

问题:这里是什么原因导致了这个问题,我该如何纠正它,以便我可以轻松地添加和居中扩展到目录中多行的文本?

谢谢。

相关内容