14

How can I put horizontal lines before and after my Table of Contents entries?

To illustrate the look and feel I am after, please take a look at this image:

enter image description here

I would like to understand how to do the same on a full ToC rather than, as it is the case in the linked image, on a "mini-ToC".

1 Answer 1

16

For the standard classes, you can use the tocloft package; using \cftaftertoctitle you can place some material (a rule and some vertical space, in this case) after the ToC title and before the entries; after the ToC is typeset a rule is inserted using \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}

enter image description here

Without additional packages, you can redefine the \tableofcontents command as implemented in the document class used. For example, using book, such a redefinition might look like this (the changes were marked with %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}

The memoir document class offers you the built-in command \aftertoctitle to add material after the ToC title:

\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}
5
  • 1
    in the visual, that's an awfully big space after the rule above the contents list. Jul 27, 2012 at 12:49
  • @barbarabeeton is it better now? (I am not sure if I corrected the right space.) Jul 27, 2012 at 14:09
  • oh, that's very much nicer! i like the fact that the spaces around the top rule and before the bottom rule look to be the same size; this balance is especially appropriate for such a short list. Jul 27, 2012 at 15:05
  • You forgot to put \subsubsection to get the "Test Section Two One One" hierarchy, you are just using all \section commands in your code. Jul 31, 2012 at 14:01
  • @Robottinosino you're right. I've updated my answer. Jul 31, 2012 at 14:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .