章节之后的章节与我获得的模板不兼容

章节之后的章节与我获得的模板不兼容

我复制了一个模板,用于为我的文档制作一个漂亮的目录。但是在我的章节中添加了一个部分后,其余章节会给出错误:“出现问题 - 可能缺少/项目”。

\documentclass[11pt, openany]{book}

\usepackage[dutch]{babel}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{lmodern}
\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}
\patchcmd{\tableofcontents}{\contentsname}{\sffamily\contentsname}{}{}

\usepackage{xcolor}
\usepackage{framed}

\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}

%\renewenvironment{leftbar}{%
%  \def\FrameCommand{{\color{myyellow}\vrule width 2pt depth 6pt} \hspace{10pt}}%
%  \MakeFramed {\advance\hsize-\width \FrameRestore}}%
% {\endMakeFramed}

\makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addtocontents{toc}%
                                   {%
                                       {\noindent\protect\parbox{3.8em}{\hfill\Huge\color{myred}\bfseries\thepage}}%
                                         \protect\hspace*{.5em}%
                                        \protect\parbox{\dimexpr\linewidth-4.5em\relax}{%
                                           \protect\begin{leftbar}
                                              {\scshape\small\chaptername~\thechapter}\\\sffamily#1%
                                           \protect\end{leftbar}}\par\noindent
                                    }%
                       \else
                         \addcontentsline{toc}{chapter}{#1}%
                       \fi
                    \else
                      \addcontentsline{toc}{chapter}{#1}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}
\makeatother
\usepackage{graphicx}
\usepackage[margin=2cm, paperwidth=210mm, paperheight=297mm]{geometry}
\begin{document}
\pagenumbering{roman}
\begin{titlepage}
\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
\center
\HRule \\[0.4cm]
{ \LARGE \bfseries P\\[0.4cm]}
\HRule \\[0,5cm]
\textsc  Gaming - KB-24  \\ [11cm]
\begin{minipage}{0.8\textwidth}
\begin{flushright} \large
 Haagse Hogeschool \\ Mi\\ R\\ 2
\end{flushright}
\end{minipage}
\\[1cm]
\begin{minipage}{0.8\textwidth}
\begin{flushright} \large
{\bf Studenten:}\\ W\\ Ak\\ L
\end{flushright}
\end{minipage}
\\[1cm]
\begin{minipage}{0.8\textwidth}
\begin{flushright} \large
{\bf Docenten:}\\ G
\\ G
\end{flushright}
\end{minipage}
\\[1cm]
\begin{minipage}{0.8\textwidth}
\begin{flushright} \large
I\\
Datum: \today \\

Versie: 0.1 \\
G
\end{flushright}
\end{minipage}
\end{titlepage}
\renewenvironment{leftbar}
  {\def\FrameCommand{\hspace{6em}%
    {\color{myyellow}\vrule width 2pt depth 6pt}\hspace{1em}}%
    \MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
  }
 {\endMakeFramed}

\titlecontents{section}
  [8.4em]
  {\sffamily\contentslabel{3em}}{}{}
  {\hspace{0.5em}\nobreak\itshape\color{myred}\contentspage}
\titlecontents{subsection}
  [8.4em]
  {\sffamily\contentslabel{3em}}{}{}  
  {\hspace{0.5em}\nobreak\itshape\color{myred}\contentspage}

\tableofcontents
\newpage

\pagenumbering{arabic}

\chapter {chapter one}
dfgdfg
\section{section one}
\newpage  
\chapter {chapter two}
\section {section one} 
\end{document}

答案1

TeX 错误行号非常准确地指出了错误的来源(一次:-) 它位于\noindent章节 toc 定义的末尾。

如果你注释掉或者删除\noindent文件第 37 行,它看起来会像这样:

                                  {\scshape\small\chaptername~\thechapter}\\\sffamily#1%
                               \protect\end{leftbar}}\par%\noindent
                        }%

然后它运行就不会出错了。

相关内容