為什麼我在這個非常簡單的 mwe 中遇到這個錯誤?

為什麼我在這個非常簡單的 mwe 中遇到這個錯誤?

為什麼我在這個非常簡單的 mwe 中遇到這個錯誤?看來同樣的錯誤出現在book二班。

\documentclass[notoc]{tufte-book}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\begin{document}

\tableofcontents
\chapter{Introduction}

\startcontents[chapters]
\printcontents[chapters]{}{1}{}

\section{Historical Overview}
\section{The CUDA Model}
\section{A Lattice Boltzmann Solver}

\addtocontents{toc}{text}

\chapter{chap3}
\section{My Overview}
\end{document}

答案1

您需要在章節行之前插入段落分隔符號。由於不允許直接使用 \par,請使用 \endgraf:

\documentclass[notoc]{tufte-book}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

\begin{document}

\tableofcontents
\chapter{Introduction}

\startcontents[chapters]
\printcontents[chapters]{}{1}{}

\section{Historical Overview}
\section{The CUDA Model}
\section{A Lattice Boltzmann Solver}

\addtocontents{toc}{text\endgraf}

\chapter{chap3}
\section{My Overview}
\end{document}

答案2

.toc它源於透過在文件中引入隨機文本

\addtocontents{toc}{text}

如果您希望這樣做,請事後發出 a 來確保文字是獨立的\par

以下最小範例複製了該問題:

\documentclass{article}

\begin{document}

\tableofcontents

\section{A section}

\addcontents{toc}{text}% Error
%\addtocontents{toc}{text\par}% No error

\section{Another section}

\end{document}

相關內容