0

I am using book class and I want to create a part in TOC in the following way:

I want the part centred in the middle of the page and the chapters on the other page.

Here is my code:

\documentclass[12pt]{book}
    \makeatletter
    \def\@part[#1]#2{%
    \ifnum \c@secnumdepth >-2\relax
      \refstepcounter{part}%
      \addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}
    \else
      \addcontentsline{toc}{part}{#1}%
    \fi
    \markboth{}{}%
    {\centering
     \interlinepenalty \@M
     \normalfont
     \ifnum \c@secnumdepth >-2\relax
       \huge\bfseries \partname\nobreakspace\thepart
       \par
       \vskip 20\p@
     \fi
     \Huge \bfseries #2\par}%
    \@endpart}
    \renewcommand\l@part[2]{%
    \thispagestyle{empty}
    \newpage 
    \vspace*{\fill}
    \begin{center}
    \def\numberline##1{%
    \Large Part~ ##1\newline
    }
    {\Huge #1}
    \end{center}
    \vspace*{\fill}
    \newpage
     }
    \makeatother

    \begin{document}


    \tableofcontents

    \part{one}

    \chapter{one \\ two}
    \chapter{two}
    \chapter{three\\three\\three\\three\\three}
    \chapter{four}

    \part{two}

    \chapter{five}
    \chapter{six}
    \chapter{seven}
    \chapter{six}
    \chapter{seven}
    \chapter{six}
    \chapter{seven}
    \end{document}

I already put the part in a separated page, but I do not know why I can not change the font size of the TOC (i.e., why \Large, \Huge do not work in \l@part) and I can not put the empty page on this too (i.e., why \thispagestyle{empty} does not work in \l@part).

0

Note the use of two sets of braces in the redefinition of \numberline. The second set makes \Large local.

Also, I wasn't sure if the use of \newline was deliberate.

\documentclass[12pt]{book}
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax
  \refstepcounter{part}%
  \addcontentsline{toc}{part}{\protect\numberline{\thepart}#1}
\else
  \addcontentsline{toc}{part}{#1}%
\fi
\markboth{}{}%
{\centering
 \interlinepenalty \@M
 \normalfont
 \ifnum \c@secnumdepth >-2\relax
   \huge\bfseries \partname\nobreakspace\thepart
   \par
   \vskip 20\p@
 \fi
 \Huge \bfseries #2\par}%
\@endpart}
\renewcommand\l@part[2]{%
\newpage 
\thispagestyle{empty}
\vspace*{\fill}
\begin{center}
\def\numberline##1{{\Large Part~ ##1\\}}%
{\Huge #1}
\end{center}
\vspace*{\fill}
\newpage
 }
\makeatother

\begin{document}

\tableofcontents

\part{one}

\chapter{one \\ two}
\chapter{two}
\chapter{three\\three\\three\\three\\three}
\chapter{four}

\part{two}

\chapter{five}
\chapter{six}
\chapter{seven}
\chapter{six}
\chapter{seven}
\chapter{six}
\chapter{seven}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.