
Meu índice não cabe em uma página, dois capítulos vão para uma nova página e o resto da página está vazio, é possível consertar isso de alguma forma?
Responder1
Usandoesseresposta antiga minha (que define a \fitbox
macro - seu nome deve ser autoexplicativo) você poderia fazer:
\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
Exemplo completo
\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}
Saída
Antes
Depois
Responder2
Você pode reduzir o espaço definidoantescada título de capítulo no ToC. O padrão é 1em
. Ou usetocloft
\usepackage{tocloft}
\setlength{\cftbeforechapskip}{0.8em}
ou através de umetoolbox
correção
\usepackage{etoolbox}
\makeatletter
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\l@chapter}{1.0em}{0.8em}{}{}
\makeatother
Aqui está um exemplo mínimo:
\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}
Antes da atualização:
Após a atualização:
Você pode ajustar o espaçamento ajustado para ajustar as coisas à sua configuração. Por exemplo, se você também tiver seções no sumário, talvez não queira ajustar \cftbeforechapskip
tanto o valor e talvez também ajustar \cftbeforesecskip
.
O procedimento acima deve funcionar para ambas book
as report
classes de documentos. Se você estiver usandomemoir
, você pode fazer algo semelhante ao que tocloft
fornece. No preâmbulo, ajuste \cftbeforechapterskip
:
\documentclass[...]{memoir}
\setlength{\cftbeforechapterskip}{0.8em}% Change to suit your needs...
...
Responder3
Considere este MWE reproduzindo o problema:
\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}
Para manter a consistência com o resto do livro, eu evitaria alterações no layout (margens e/ou espaço ao redor do título, \enlargethispage{}
etc.) ou redimensionamento de uma caixa contendo o ToC, pois isso poderia produzir um tamanho de fonte não padrão (que será não usado no resto do livro).
Minha sugestão é mais simples: use uma fonte padrão menor (por exemplo, \footnotesize
), reduza um pouco o espaçamento entre linhas (por exemplo, \linespread{.85}
) ou misture as duas abordagens para uma mudança de estilo mais sutil:
\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}