我注意到我的目录在奇怪的地方断了。除非整个章节可以放在当前页面上,否则它会在章节标题后立即断掉。此外,如果章节包含太多项目,列表会从页面底部溢出,而不是断掉。我该如何修复这个问题?
在发布的 MWE 中,目录的第一页仅部分填充,并且在第 2 章章节标题项后分页,而第二页则更紧凑。如果您更改第 2 章中的节数,页面分割的位置会发生变化。因此,正在发生某种“平衡”内容量 - 虽然不是以一种好的方式。
如果没有反向链接代码就不会发生这种情况 - 但我想要这个功能!
我认为这里的代码解决方案可能是我需要添加的,但我不知道在哪里/如何添加:允许在目录中的部分内容后进行分页
MWE 如下:
\documentclass{book}
\usepackage[pdfpagemode={UseOutlines},bookmarks=true,bookmarksopen=true,
bookmarksopenlevel=0,bookmarksnumbered=true,hypertexnames=true, plainpages=false,
colorlinks,linkcolor={blue},citecolor={green},urlcolor={red},
pdfstartview={FitV},unicode,breaklinks=true,pdfpagelabels]{hyperref}
% back-link code from https://tex.stackexchange.com/questions/251904/hyperlinks-from-chapter-and-section-headings-back-to-the-table-of-contents/
\makeatletter
% configure chapter back-links
\let\hyperchapter\chapter
\def\chapter{\@ifstar\starchapter\mychapter}
\def\starchapter{\hyperchapter*}
\newcommand{\mychapter}[2][\@empty]% #1=optional (toc and top of page), #2=title
{\ifx#1\@empty \hyperchapter[#2]{\hyperlink{toc.chapter.\thechapter}{#2}}
\else \hyperchapter[#1]{\hyperlink{toc.chapter.\thechapter}{#2}}
\fi}
% configure section back-links
\let\hypersection\section
\def\section{\@ifstar\starsection\mysection}
\def\starsection{\hypersection*}
\newcommand{\mysection}[2][\@empty]% #1=optional (toc), #2=title
{\ifx#1\@empty \hypersection[#2]{\hyperlink{toc.section.\thesection}{#2}}
\else \hypersection[#1]{\hyperlink{toc.section.\thesection}{#2}}
\fi}
% configure subsection back-links
\let\hypersubsection\subsection
\def\subsection{\@ifstar\starsubsection\mysubsection}
\def\starsubsection{\hypersubsection*}
\newcommand{\mysubsection}[2][\@empty]% #1=optional (toc), #2=title
{\ifx#1\@empty \hypersubsection[#2]{\hyperlink{toc.subsection.\thesubsection}{#2}}
\else \hypersubsection[#1]{\hyperlink{toc.subsection.\thesubsection}{#2}}
\fi}
% configure subsubsection back-links
\let\hypersubsubsection\subsubsection
\def\subsubsection{\@ifstar\starsubsubsection\mysubsubsection}
\def\starsubsubsection{\hypersubsubsection*}
\newcommand{\mysubsubsection}[2][\@empty]% #1=optional (toc), #2=title
{\ifx#1\@empty \hypersubsubsection[#2]{\hyperlink{toc.subsubsection.\thesubsubsection}{#2}}
\else \hypersubsubsection[#1]{\hyperlink{toc.subsubsection.\thesubsubsection}{#2}}
\fi}
% close out
\makeatother
\begin{document}
%%%---Set up clickable section headers----------
\let\hypercontentsline=\contentsline
\renewcommand{\contentsline}[4]{\hypertarget{toc.#4}{}\hypercontentsline{#1}{#2}{#3}{#4}}
%%%---End set up clickable section headers----------
\tableofcontents
\chapter{The First}
\section{ant}
\subsection{bee}
\subsubsection{cow}
\section{dog}
\subsection{eel}
\subsubsection{fly}
\chapter{The Second}
\section{ant1}
\subsection{bee1}
\subsubsection{cow1}
\section{dog1}
\subsection{eel1}
\subsubsection{fly1}
\section{ant2}
\subsection{bee2}
\subsubsection{cow2}
\section{dog2}
\subsection{eel2}
\subsubsection{fly2}
\section{ant3}
\subsection{bee3}
\subsubsection{cow3}
\section{dog3}
\subsection{eel3}
\subsubsection{fly3}
\section{ant4}
\subsection{bee4}
\subsubsection{cow4}
\section{dog4}
\subsection{eel4}
\subsubsection{fly4}
\section{ant41}
\subsection{bee41}
\subsubsection{cow41}
\section{dog41}
\subsection{eel41}
\subsubsection{fly41}
\section{ant42}
\subsection{bee42}
\subsubsection{cow42}
\section{dog42}
\subsection{eel42}
\subsubsection{fly42}
\section{ant43}
\subsection{bee43}
\subsubsection{cow43}
\section{dog43}
\subsection{eel43}
\subsubsection{fly43}
\chapter{The Third}
\section{ant5}
\subsection{bee5}
\subsubsection{cow5}
\section{dog5}
\subsection{eel5}
\subsubsection{fly5}
\section{ant6}
\subsection{bee6}
\subsubsection{cow6}
\section{dog6}
\subsection{eel6}
\subsubsection{fly6}
\section{ant7}
\subsection{bee7}
\subsubsection{cow7}
\section{dog7}
\subsection{eel7}
\subsubsection{fly7}
\section{ant8}
\subsection{bee8}
\subsubsection{cow8}
\section{dog8}
\subsection{eel8}
\subsubsection{fly8}
\end{document}
答案1
[...]
\subsubsection{fly}
\addtocontents{toc}{\protect\newpage}
\chapter{The Second}
[...]