5

I am using "The Legrand Orange Book" template from Mathias Legrand on http://www.LaTeXTemplates.com for a collection of "some" poems and unfortunately I run into a problem, I can't handle myself:

I have so many sections, that the list in the toc is somehow miss-printed. Is it possible to set a max. number of items for the toc and then let a new page start with the other items?

I have provided a picture with my problem and also contacted the developer, but he answered:

... part page cannot spread over more than one page because of the use of Tikz and a \parbox. See below in structure.tex

\node[anchor=south east] at (\paperwidth-1cm,-\paperheight+1cm){\parbox[t][][t]{8.5cm}{
\printcontents{l}{0}{\setcounter{tocdepth}{1}}}};, hope you will be able to

Hope someone here can help :) Thanks and happy x-mas by the way :)

too many items in part of toc

  • 1
    Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. A screen shot is nice, but does not show what you've done –  Dec 24 '15 at 12:44
  • I can imagine an entry counter after which an \addtocontents{toc}{\clearpage} will be inserted. –  Dec 24 '15 at 12:49
  • Isn't the whole idea of a toc to have all entries in there? – Rico Dec 24 '15 at 12:50
  • @Rico: Yes, but I understood the question different: Apparently, the page is overloaded, i.e. too much ToC entries on the same page without floating to the next page –  Dec 24 '15 at 12:51
  • Maybe a titletoccould work? something like the top answer by Gonzala Medina in http://tex.stackexchange.com/questions/48900/two-independent-tocs

    Would require manual breaking of sections, but this should be done when the article should be published.

    – Runar Dec 24 '15 at 12:56

2 Answers2

5

Here is a solution we save the partial toc in \vbox and use \vsplit

 \global\setbox\mtpbox=\vbox{\printcontents{l}{0}{\setcounter{tocdepth}{1}}}

complete code

\documentclass[11pt,fleqn]{book} 
\input{structure} 

\newbox\mtpbox

\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax%
\refstepcounter{part}%
\addcontentsline{toc}{part}{\texorpdfstring{\protect\@mypartnumtocformat{\thepart}{#1}}{\partname~\thepart\ ---\ #1}}
\else%
\addcontentsline{toc}{part}{\texorpdfstring{\protect\@myparttocformat{#1}}{#1}}%
\fi%
\startcontents%
\markboth{}{}%
{\thispagestyle{empty}%
\global\setbox\mtpbox=\vbox{\printcontents{l}{0}{\setcounter{tocdepth}{1}}}
\begin{tikzpicture}[remember picture,overlay]%
\node at (current page.north west){\begin{tikzpicture}[remember picture,overlay]%   
\fill[ocre!20](0cm,0cm) rectangle (\paperwidth,-\paperheight);
\node[anchor=north] at (4cm,-3.25cm){\color{ocre!40}\fontsize{220}{100}\sffamily\bfseries\@Roman\c@part}; 
\node[anchor=south east] at (\paperwidth-1cm,-\paperheight+1cm){\parbox[t][][t]{8.5cm}{
\ifdim\ht\mtpbox<\textheight\box\mtpbox\else\vsplit\mtpbox to 15\baselineskip\fi%
}};
\node[anchor=north east] at (\paperwidth-1.5cm,-3.25cm){\parbox[t][][t]{15cm}{\strut\raggedleft\color{white}\fontsize{30}{30}\sffamily\bfseries#2}};
\end{tikzpicture}};
\end{tikzpicture}}%
\@endpart}

\def\@endpart{\vfil\newpage
\ifvoid\mtpbox\else\unvbox\mtpbox\vfil\newpage\fi
\ifodd\value{page}\else
\if@twoside
\if@openright
\null
\thispagestyle{empty}%
\newpage
\fi
\fi
\if@tempswa
\twocolumn
\fi\fi}
\makeatother

\begin{document}

\part{Part One}
\foreach \x in {1,...,30} {
\chapter{A chapter with number \x}
\section{A section}
\subsection{A subsection}
}


\part{Part One}
\foreach \x in {1,...,36} {
\chapter{A chapter with number \x}
\section{A section}
\subsection{A subsection}
}
\end{document}

Update: changes commented in code

\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax%
\refstepcounter{part}%
\addcontentsline{toc}{part}{\texorpdfstring{\protect\@mypartnumtocformat{\thepart}{#1}}{\partname~\thepart\ ---\ #1}}
\else%
\addcontentsline{toc}{part}{\texorpdfstring{\protect\@myparttocformat{#1}}{#1}}%
\fi%
\startcontents%
\markboth{}{}%
{\pagestyle{empty}%
\global\setbox\mtpbox=\vbox{\printcontents{l}{0}{\setcounter{tocdepth}{1}}}
\loop    %  use a boocle: loop
\begin{tikzpicture}[remember picture,overlay]%
\node at (current page.north west){\begin{tikzpicture}[remember picture,overlay]%   
\fill[ocre!20](0cm,0cm) rectangle (\paperwidth,-\paperheight);
\node[anchor=north] at (4cm,-3.25cm){\color{ocre!40}\fontsize{220}{100}\sffamily\bfseries\@Roman\c@part}; 
\node[anchor=south east] at (\paperwidth-1cm,-\paperheight+1cm){\parbox[t][][t]{8.5cm}{
\ifdim\ht\mtpbox<16\baselineskip\box\mtpbox\else\vsplit\mtpbox to 15\baselineskip\fi%  
 % rather then \textheight we use 16\baselineskip for example
}};
\node[anchor=north east] at (\paperwidth-1.5cm,-3.25cm){\parbox[t][][t]{15cm}{\strut\raggedleft\color{white}\fontsize{30}{30}\sffamily\bfseries#2}};
\end{tikzpicture}};
\end{tikzpicture}%
\vfil\newpage  % go to next page
\unless\ifvoid\mtpbox\repeat} % end of boocle
\@endpart}

\def\@endpart{\vfil\newpage
%\ifvoid\mtpbox\else\unvbox\mtpbox\vfil\newpage\fi  % not used any more
\ifodd\value{page}\else
\if@twoside
\if@openright
\null
\thispagestyle{empty}%
\newpage
\fi
\fi
\if@tempswa
\twocolumn
\fi\fi}
\makeatother
touhami
  • 19,520
4

Here's a proposition (however, not for the 'famous' Orange Book, but it works with that too, I've checked!)

\documentclass{book}
% Insert this to the file of the thesis
\newcounter{limitperpage}
\setcounter{limitperpage}{15}

\newcounter{tocentries}

\usepackage{xpatch}

\xapptocmd{\addcontentsline}{\ifstrequal{#1}{toc}{%
    \stepcounter{tocentries}%
    }{}%
    \ifnum\value{tocentries} = \value{limitperpage} 
    \addtocontents{toc}{\protect\clearpage}%
    \setcounter{tocentries}{0}%
    \fi
}{}{}

%before \begin{document}


\usepackage{pgffor}

\begin{document}
\tableofcontents
\foreach \x in {1,...,100} {
\chapter{A chapter with number \x}
\section{A section}
\subsection{A subsection}
}

\end{document}

enter image description here