0

So I imported a part of a latex code to make a good table of contents, but it gives me an extra page after every chapter which I don't want.

\documentclass[11pt]{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}%
                                   {%
                                       {\protect\parbox{3.5em}{\hfill\Huge\color{myred}\bfseries\thepage}}%
                                         \protect\hspace*{.5em}
                                        \protect\parbox{\dimexpr\linewidth-4em\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}
\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{chapter}
  [0em]{\vspace*{2\baselineskip}}
  {\parbox{4.5em}{%
    \hfill\Huge\sffamily\bfseries\color{myred}\thecontentspage}%
   \vspace*{-2.3\baselineskip}\leftbar\textsc{\small\chaptername~\thecontentslabel}\\\sffamily}
  {}{\endleftbar}
\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}
\section{sectionone}
some text
\chapter {chapter two}
\end{document}
  • it is normal for chapter titles to be forced to right hand (odd pages). You can overide that with openany option on the \documentclass (but chapter opening on the left can look odd. If that is the issue then this question will be a duplicate (if I find it..) – David Carlisle Nov 22 '14 at 23:42
  • yup openany fixed it, im sorry for duplicate – user3201911 Nov 22 '14 at 23:50
  • That's OK glad you got it working (but look through your books, you will not find many starting chapters on the left:-) – David Carlisle Nov 22 '14 at 23:52
  • Yes you are right, this document is actually for my schoolproject. Maybe it looks better when I put the chapters in the middle? – user3201911 Nov 22 '14 at 23:58
  • Also, my format isn't going that well. In my example above, the second chapter is going a little bit to the right. – user3201911 Nov 23 '14 at 00:06
  • user it doesn't really work to ask further questions in comments, no answers can be given once the question is marked as duplicate (and most people wont see the comment) feel free to ask another question about alignment with an example showing that. if you have openany of course the headings fit to the odd and even margins (which are not equal) – David Carlisle Nov 23 '14 at 00:09
  • Thanks, I will ask a new question. Thanks for helping me out David! – user3201911 Nov 23 '14 at 00:11

0 Answers0