考虑一下代码
\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}]
我收到以下错误显示:
问题:这里是什么原因导致了这个问题,我该如何纠正它,以便我可以轻松地添加和居中扩展到目录中多行的文本?
谢谢。