[Tex/LaTex] Table of Contents horizontal lines

rulestable of contents

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".

Best Answer

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}