目录水平线

目录水平线

如何在目录条目前后添加水平线?

为了说明我所追求的外观和感觉,请看一下这张图片:

在此处输入图片描述

我想了解如何在完整的目录中执行相同操作,而不是像链接图像中那样在“迷你目录”上执行相同操作。

答案1

对于标准课程,您可以使用tocloft包;使用\cftaftertoctitle您可以在目录标题之后和条目之前放置一些材料(在本例中是规则和一些垂直空间);在目录排版之后,使用以下命令插入一条规则\hrulefill

\documentclass{book}
\usepackage{tocloft}

\renewcommand\cftaftertoctitle{\par\noindent\hrulefill\par\vskip-4.3em}

\begin{document}

\tableofcontents
\noindent\hrulefill

\chapter{Test Chapter One}
\section{Test Section One One}
\subsection{Test Subsection One One One}
\section{Test Section One Two}
\subsection{Test Subsection One Two One}
\chapter{Test Chapter Two}
\section{Test Section Two One}
\subsection{Test Subsection Two One One}
\section{Test Section Two Two}
\subsection{Test Subsection Two Two One}

\end{document}

在此处输入图片描述

无需额外的软件包,您可以重新定义\tableofcontents所使用的文档类中实现的命令。例如,使用book,这样的重新定义可能看起来像这样(更改以 标记%NEW):

\documentclass{book}

\makeatletter
\renewcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \par\noindent\hrulefill\par%NEW
    \@starttoc{toc}%
    \noindent\hrulefill%NEW
    \if@restonecol\twocolumn\fi
    }
\makeatother

\begin{document}

\tableofcontents

\chapter{Test Chapter One}
\section{Test Section One One}
\subsection{Test Subsection One One One}
\section{Test Section One Two}
\subsection{Test Subsection One Two One}
\chapter{Test Chapter Two}
\section{Test Section Two One}
\subsection{Test Subsection Two One One}
\section{Test Section Two Two}
\subsection{Test Subsection Two Two One}

\end{document}

文档类为您提供了在目录标题后添加材料的memoir内置命令:\aftertoctitle

\documentclass{memoir}

\renewcommand\aftertoctitle{\par\noindent\hrulefill\par}

\begin{document}

\tableofcontents*
\noindent\hrulefill

\chapter{Test Chapter One}
\section{Test Section One One}
\subsection{Test Subsection One One One}
\section{Test Section One Two}
\subsection{Test Subsection One Two One}
\chapter{Test Chapter Two}
\section{Test Section Two One}
\subsection{Test Subsection Two One One}
\section{Test Section Two Two}
\subsection{Test Subsection Two Two One}

\end{document}

相关内容