
目次が 1 ページに収まらず、2 つの章が新しいページに移動され、ページの残りの部分は空白になっています。これを修正することは可能ですか?
答え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}
アップデート前:
アップデート後:
調整された間隔を微調整して、設定に合うようにすることができます。たとえば、ToC にもセクションがある場合は、 の値を\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}