You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用tufte-book时含换行的标题无法生成目录,求解决方法

解决tufte-book标题换行导致目录生成失败的问题

问题原因

tufte-book文档类对标题中直接使用\\的处理逻辑与book类不同:它会将标题里的\\转换为目录环境无法识别的\centercr命令,从而触发大量语法错误,导致目录无法正常生成。

解决方案

方案1:仅正文标题换行,目录标题单行显示

如果不需要目录中的标题换行,仅需正文中标题换行,使用\texorpdfstring分别定义正文和目录的标题内容:

\section{\texorpdfstring{03title section title first line   \\ second line of title}{03title section title first line   second line of title}}

第一个花括号内是正文中显示的带换行的标题,第二个花括号内是目录中显示的单行标题。

方案2:正文和目录标题均换行显示

若需要正文和目录里的标题都换行,需要修改tufte-book的目录处理逻辑,同时用\protect\\par替代直接的\\:

完整可运行的MWE如下:

\documentclass[]{tufte-book}
\usepackage{makeidx}
\makeindex
\setcounter{tocdepth}{4}   

% 修复目录中标题换行的解析逻辑
\makeatletter
\def\@tufte@toc@line#1#2#3{%
  \ifnum \c@tocdepth > #1\relax
    \begingroup
      \@tufte@toc@style
      \settowidth{\@tempdima}{\@tufte@toc@num@format{#2}}%
      \setlength{\leftskip}{\@tempdima}%
      \setlength{\parindent}{-\@tempdima}%
      \@tufte@toc@num@format{#2}\nobreak\hskip0pt plus 1filll\relax
      #3\nobreak\hfill\nobreak\makebox[0pt][r]{\@tufte@page@format{\pageref{#3}}}\par
    \endgroup
  \fi
}
\makeatother
 
\begin{document}
\tableofcontents
 
\chapter{ix-hl1 Chapter Title} 
Introductory text for chapter.

\section{03title section title first line   \protect\\par second line of title}
section text
 
\printindex
\end{document}

错误信息翻译

你遇到的报错核心是\centercr命令未定义引发的连锁问题,具体错误翻译如下:

  • Something's wrong--perhaps a missing \item. → 出现错误——可能缺失了\item
  • Missing number, treated as zero. → 缺失数字,已视为0处理
  • Missing $ inserted. → 缺失$,已自动插入
  • Undefined control sequence. → 未定义的控制序列
  • LaTeX hooks Error: Illegal mode change in hook 'para/begin'. → LaTeX钩子错误:钩子para/begin中存在非法模式变更
  • You can't use \lastbox' in math mode. → 无法在数学模式中使用\lastbox`
  • There's no line here to end. → 此处无行可结束
  • Missing } inserted. → 缺失},已自动插入
  • Missing \endgroup inserted. → 缺失\endgroup,已自动插入
  • Extra }, or forgotten $. → 多余的},或遗漏了$
  • Extra }, or forgotten \endgroup. → 多余的},或遗漏了\endgroup
  • \begin{adjustwidth} on input line 2 ended by \end{list}. → 第2行开始的adjustwidth环境被\end{list}结束
  • \begin{fullwidth} on input line 2 ended by \end{adjustwidth}. → 第2行开始的fullwidth环境被\end{adjustwidth}结束
  • \begin{document} ended by \end{fullwidth}. → document环境被\end{fullwidth}结束
  • Extra \endgroup. → 多余的\endgroup
  • No file exampleTOC.bbl. → 未找到exampleTOC.bbl文件
  • Overfull \hbox (0.4013pt too wide) in paragraph → 段落中存在超宽hbox(超出0.4013pt)

内容的提问来源于stack exchange,提问作者user855443

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 06:36:06