Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 13 down vote accepted

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}
share|improve this answer
1  
in the visual, that's an awfully big space after the rule above the contents list. –  barbara beeton Jul 27 '12 at 12:49
    
@barbarabeeton is it better now? (I am not sure if I corrected the right space.) –  Gonzalo Medina Jul 27 '12 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. –  barbara beeton Jul 27 '12 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. –  Robottinosino Jul 31 '12 at 14:01
    
@Robottinosino you're right. I've updated my answer. –  Gonzalo Medina Jul 31 '12 at 14:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.