목차를 한 페이지에 맞추기

목차를 한 페이지에 맞추기

내 목차가 한 페이지에 맞지 않고 두 장이 새 페이지로 이동하고 나머지 페이지가 비어 있습니다. 어떻게든 이 문제를 해결할 수 있습니까?

답변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}

산출

전에

출력_1

후에

출력_2

답변2

세트 공간을 줄일 수 있습니다~ 전에ToC의 각 장 제목. 기본값은 입니다 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.


위의 내용은 bookreport문서 클래스 모두에서 작동합니다. 당신이 사용하는 경우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{}등)을 변경하거나 ToC가 포함된 상자의 크기를 조정하지 않을 것입니다. 책의 나머지 부분에서는 사용되지 않음).

내 제안은 더 간단합니다. 더 작은 표준 글꼴(예: \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}

해결책

관련 정보