我正在用 LaTex 写一本有 20 多个章节的书。我用 tocloft 包生成了详细的目录,用 shorttoc 生成了简短的目录。现在,简短的目录有两页,但我真的希望它只有一页长。来自 tocloft 的命令只能控制简短目录中的一些功能。我在最后附上了我的示例代码。具体来说,我的问题如下。非常感谢您的帮助。-- Edwin
问题 1:如何才能调整简短目录中的行距,使其长度达到一页?
问题2:如何调整“简要内容”标题前后的间距?
问题 3:如何从简要目录中删除“目录”条目?
---- 示例代码 -----------------
\documentclass{book}
% 1. load two packges
\usepackage[tight]{shorttoc}
\usepackage{tocloft}
% 2. add a line below part title in TOC
\makeatletter
\renewcommand{\@tocrmarg}{0em}
\renewcommand\cftpartafterpnum{\par\vskip-2ex\hrulefill\par}
\makeatother
% 3. adjust vertical space in TOC
\setlength\cftbeforetoctitleskip{0pt} % change space before TOC title
\setlength\cftaftertoctitleskip{0pt} % change space after TOC title
\setlength\cftbeforepartskip{16pt} % change space before part
\setlength\cftbeforechapskip{8pt} % change space before chapter
%\setlength\cftbeforesecskip{1pt} % change space before section
%\setlength\cftparskip{-2pt} % distance between paragraphs/entry; default 0
\begin{document}
% 4. add brief TOC
\clearpage \phantomsection
\shorttoc{Brief Contents}{0}
% 5. add detailed TOC
\clearpage \phantomsection
\setcounter{tocdepth}{2}
\addcontentsline{toc}{chapter}{Contents} % add a link for Contents in TOC
\tableofcontents
\part{Part 1}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 2}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 3}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 4}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 5}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 6}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 7}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 8}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\end{document}
答案1
我不知道如何使用shorttoc
,但这里有一个可能性,使用强大的titletoc
包裹:
\documentclass{book}
\usepackage{titletoc}
\usepackage{tocloft}
\makeatletter
\renewcommand{\@tocrmarg}{0em}
\renewcommand\cftpartafterpnum{\par\vskip-2ex\hrulefill\par}
\makeatother
\setlength\cftbeforetoctitleskip{0pt} % change space before TOC title
\setlength\cftaftertoctitleskip{0pt} % change space after TOC title
\setlength\cftbeforepartskip{16pt} % change space before part
\setlength\cftbeforechapskip{8pt} % change space before chapter
\titlecontents{schapter}
[27pt]
{\bfseries}
{\contentslabel{27pt}}
{\hspace*{-27pt}}
{\titlerule*[100pc]{.}\contentspage}
\titlecontents{spart}
[27pt]
{\large\bfseries\vskip5pt}
{\contentslabel{27pt}}
{\hspace*{-27pt}}
{\titlerule*[100pc]{.}\contentspage}[\vskip-2ex\hrulefill{\\*[-1.8ex]}]
\begin{document}
\startcontents[short]
\clearpage
\phantomsection
\printcontents[short]{s}{-1}{%
\setcounter{tocdepth}{0}%
\noindent{\Huge\bfseries Brief Contents}\par\bigskip%
}
\clearpage
\phantomsection
\setcounter{tocdepth}{2}
\addtocontents{toc}{}
\stopcontents[short]
\addcontentsline{toc}{chapter}{Contents} % add a link for Contents in TOC
\tableofcontents
\resumecontents[short]
\part{Part 1}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 2}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 3}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 4}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 5}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 6}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 7}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\part{Part 8}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\chapter{Test Chapter} \section{Test Section} \section{Test Section}
\end{document}
生成的 ToC 的图像显示了所请求的功能: