完成主要编辑,使问题清晰。
删除最后一章行有效。但保留它会让 latex 发疯。它会打印数字直到 65536.. 并出现错误:** 错误 ** 页码 65536l 太大!
MikTex、XeLatex、PdfLatex(忍受了更多部分,但仍然出现同样的错误)。
深入研究后,我发现问题出在 mdframed,特别是 usetwoside 选项上。该错误似乎也是以下警告的结果:
http://en.wikibooks.org/wiki/LaTeX/Errors_and_Warnings#Underfull_hbox
日志在这里:http://pastebin.com/Qw58ajKF
\documentclass{book}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{titletoc}
\usepackage{etoolbox}
\definecolor{secnum}{RGB}{13,151,225}
\definecolor{ptcbackground}{RGB}{212,237,252}
\definecolor{ptctitle}{RGB}{0,177,235}
\pretocmd{\tableofcontents}{\begin{mdframed}[backgroundcolor=ptcbackground,hidealllines=true]}{}{}
\apptocmd{\tableofcontents}{\end{mdframed}}{}{}
\patchcmd{\tableofcontents}{\contentsname}{\color{ptctitle}\contentsname}{}{}
\setcounter{tocdepth}{1}
\titlecontents{section}
[4em]{\sffamily}
{\color{secnum}\contentslabel{2.3em}\normalcolor}{}
{\titlerule*[1000pc]{.}\contentspage\\\hspace*{-3em}\vspace*{2pt}%
\color{white}\rule{\dimexpr\textwidth-20pt\relax}{1pt}}
\titlecontents{lsection}
[5.8em]{\sffamily}
{\color{secnum}\contentslabel{2.3em}\normalcolor}{}
{\titlerule*[1000pc]{.}\contentspage\\\hspace*{-5.8em}\vspace*{2pt}%
\color{white}\rule{\dimexpr\textwidth-15.5pt\relax}{1pt}}
\makeatletter
\renewcommand*\l@chapter[2]{%
\ifnum \c@tocdepth >\m@ne
\addpenalty{-\@highpenalty}%
\vskip 1.0em \@plus\p@
\setlength\@tempdima{1.5em}%
\begingroup
\parindent \z@ \rightskip \@pnumwidth
\parfillskip -\@pnumwidth
\leavevmode
\advance\leftskip\@tempdima
\hskip -\leftskip
\colorbox{ptctitle}{\strut%
\makebox[\dimexpr\textwidth-2\fboxsep-7pt\relax][l]{%
\color{white}\bfseries\sffamily#1%
\nobreak\hfill\nobreak\hb@xt@\@pnumwidth{\hss #2}}}\par\smallskip
\penalty\@highpenalty
\endgroup
\fi}
\makeatother
\newcommand\PartialToC{%
\startcontents[chapters]%
\begin{mdframed}[backgroundcolor=ptcbackground,hidealllines=true]
\printcontents[chapters]{l}{1}{\colorbox{ptctitle}{%
\parbox[t]{\dimexpr\textwidth-2\fboxsep\relax}{%
\strut\color{white}\bfseries\sffamily\makebox[5em]{%
Chapter~\thechapter\hfill}Contents}}\vskip5pt}
\end{mdframed}%
}
\begin{document}
\tableofcontents
\chapter{Chapter One}
\PartialToC
\section{Section One One}
\section{Section One Two}
\section{Section One Three}
\section{Section One Four}
\stopcontents[chapters]
\chapter{Chapter Two}
\PartialToC
\section{Section Two One}
\section{Section Two Two}
\section{Section Two Three}
\stopcontents[chapters]
\chapter{Chapter Three}
\PartialToC
\section{Section Three One}
\section{Section Three Two}
\section{Section Three Three}
\section{Section Three Four}
\section{Section Three Five}
\stopcontents[chapters]
\chapter{Chapter Three}
\end{document}
答案1
该命令在开始时\tableofcontents
执行。这会导致无限循环。只需将以下行更改为:\cleardoublepage
\pretocmd{\tableofcontents}{\begin{mdframed}[backgroundcolor=ptcbackground,hidealllines=true]}{}{}
到
\pretocmd{\tableofcontents}{\begin{mdframed}[backgroundcolor=ptcbackground,hidealllines=true]\let\cleardoublepage\relax}{}{}
一切运行良好。