![居中命令在目录之外工作正常;但在目录内部则完全不同](https://linux22.com/image/445976/%E5%B1%85%E4%B8%AD%E5%91%BD%E4%BB%A4%E5%9C%A8%E7%9B%AE%E5%BD%95%E4%B9%8B%E5%A4%96%E5%B7%A5%E4%BD%9C%E6%AD%A3%E5%B8%B8%EF%BC%9B%E4%BD%86%E5%9C%A8%E7%9B%AE%E5%BD%95%E5%86%85%E9%83%A8%E5%88%99%E5%AE%8C%E5%85%A8%E4%B8%8D%E5%90%8C.png)
考虑一下代码
\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}]
我收到以下错误显示:
问题:这里是什么原因导致了这个问题,我该如何纠正它,以便我可以轻松地添加和居中扩展到目录中多行的文本?
谢谢。