目录中的项目太多

目录中的项目太多

我正在使用 Mathias Legrand 的“Legrand Orange Book”模板http://www.LaTeXTemplates.com收集“一些”诗歌,不幸的是我遇到了一个问题,我无法处理自己:

我有太多章节,以至于目录中的列表不知为何打印错误。是否可以设置目录中的最大项目数,然后让新页面从其他项目开始?

我提供了一张显示我的问题的图片,并联系了开发人员,但他回答说:

... 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

希望这里有人可以帮忙 :) 谢谢,顺便祝圣诞快乐 :)

部分目录中的项目过多

答案1

这是一个解决方案,我们保存部分目录\vbox并使用\vsplit

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

完整代码

\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}

更新:代码中注释的更改

\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

答案2

这是一个提议(然而,它不适用于‘著名的’橙皮书,但它也适用于它,我已经检查过了!)

\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}

在此处输入图片描述

相关内容