
我的目錄不適合一頁,兩章轉到新頁面,頁面的其餘部分是空的,是否可以以某種方式解決此問題?
答案1
使用這我的舊答案(定義了\fitbox
宏——它的名字應該是不言自明的)你可以這樣做:
\makeatletter
\let\oldtableofcontents\tableofcontents
\renewcommand\tableofcontents{%
\begingroup
\@fileswfalse
\fitbox\textheight{\oldtableofcontents}
\endgroup
\if@filesw
\expandafter\newwrite\csname tf@toc\endcsname
\immediate\openout \csname tf@toc\endcsname \jobname.toc\relax
\fi
}
\makeatother
完整範例
\documentclass{article}
\usepackage{lipsum}
\renewcommand{\rmdefault}{ppl}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{fp,graphicx}
\setlength\unitlength{1cm}
\makeatletter
\def\accur@cy{0.999}
\newcommand{\fitbox}[3][\textwidth]{%
\@tempdima#2
\edef\@wd{\strip@pt\dimexpr#1\relax}
\def\r@tio{1}
\@temptokena={\scalebox{\r@tio}{\parbox{\@wd pt}{{#3}}}}
\setbox0=\vbox{\the\@temptokena}
\@tempdimb=\dimexpr\ht0+\dp0\relax
\FPdiv\r@tio{\strip@pt\@tempdima}{\strip@pt\@tempdimb}
\FProot\r@tio{\r@tio}{2}
\FPdiv\@wd{\@wd}{\r@tio}
\fitbox@adjust
\setbox0=\vbox{\the\@temptokena}
\box0
}
\newcommand{\fitbox@adjust}{%
\@tempcnta\z@
\def\rel@rror@rec{0}
\fitbox@adjust@
}
\newcommand{\fitbox@adjust@}{%
\advance\@tempcnta by 1
\ifnum\@tempcnta<10
\FPiflt\rel@rror@rec\accur@cy
\setbox0=\vbox{\the\@temptokena}
\@tempdimb=\dimexpr\ht0+\dp0\relax
\FPdiv\rel@rror@rec{\strip@pt\@tempdimb}{\strip@pt\@tempdima}
\FPdiv\r@tio{\r@tio}{\rel@rror@rec}
\FPmul\@wd{\@wd}{\rel@rror@rec}
\fitbox@adjust@
\fi
\fi
}
\let\oldtableofcontents\tableofcontents
\renewcommand\tableofcontents{%
\begingroup
\@fileswfalse
\fitbox\textheight{\oldtableofcontents}
\endgroup
\if@filesw
\expandafter\newwrite\csname tf@toc\endcsname
\immediate\openout \csname tf@toc\endcsname \jobname.toc\relax
\fi
}
\makeatother
\begin{document}
\tableofcontents
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\section{hello world}
\end{document}
輸出
前
後
答案2
您可以減少空間設置前目錄中的每個章節標題。預設為1em
.要么使用tocloft
\usepackage{tocloft}
\setlength{\cftbeforechapskip}{0.8em}
或透過etoolbox
修補
\usepackage{etoolbox}
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@chapter}{1.0em}{0.8em}{}{}
\makeatother
這是一個最小的例子:
\documentclass{report}
\usepackage[a5paper]{geometry}
\usepackage{tocloft}
\setlength{\cftbeforechapskip}{0.8em}
\begin{document}
\tableofcontents
\chapter{First chapter}
\chapter{Second chapter}
\chapter{Third chapter}
\chapter{Fourth chapter}
\chapter{Fifth chapter}
\chapter{Sixth chapter}
\chapter{Seventh chapter}
\chapter{Eighth chapter}
\chapter{Ninth chapter}
\chapter{Tenth chapter}
\chapter{Eleventh chapter}
\chapter{Twelfth chapter}
\chapter{Thirteenth chapter}
\chapter{Fourteenth chapter}
\end{document}
更新前:
更新後:
您可以調整調整後的間距,使其適合您的設定。例如,如果目錄中也有部分,您可能不想調整 的值\cftbeforechapskip
那麼多,也許也不想調整\cftbeforesecskip
。
上面的內容應該適用於book
和report
文檔類別。如果您正在使用memoir
,您可以執行類似tocloft
提供的操作。在序言中,調整\cftbeforechapterskip
:
\documentclass[...]{memoir}
\setlength{\cftbeforechapterskip}{0.8em}% Change to suit your needs...
...
答案3
考慮這個 MWE 重現問題:
\documentclass[oneside]{book}
\usepackage{tikz,lipsum} % for dummy text loop
\begin{document}
\tableofcontents
\foreach \x in {1,2,...,21} {\chapter{blabla\x} \lipsum[\x]}
\end{document}
為了與本書的其餘部分保持一致,我會避免更改版面(標題周圍的邊距和/或空間\enlargethispage{}
等)或調整包含目錄的框的大小,因為這可能會產生非標準字體大小(這將是本書其餘部分未使用)。
我的建議更簡單:使用較小的標準字體(例如, \footnotesize
),減少一點行間距(例如, \linespread{.85}
)或混合兩種方法以獲得更微妙的樣式變化:
\documentclass[oneside]{book}
\usepackage{tikz,lipsum} % for dummy text loop
\begin{document}
{\linespread{.95}\small\tableofcontents}
\foreach \x in {1,2,...,21} {\chapter{blabla\x} \lipsum[\x]}
\end{document}