# babel and \contentsname, how to add extra customization?

This is what I'm trying to do:

\renewcommand{\contentsname}{
\vspace{-8mm}
\rule{\linewidth}{0.5mm} \\[-4mm]
}


Using babel, I can get this code to work:

\documentclass[12pt]{article}
\usepackage[english]{babel}

\renewcommand{\contentsname}
%\vspace{10mm}
}

\begin{document}
\tableofcontents
\end{document}


but the second I try to add in that \vspace as a test, it fails. Any ideas how to fix this? Because I really want to add those options to the table of contents and I need the babel package as well.

-
\contentsname should contain only a string. Formatting changes to the table of contents should be made by modifying \tableofcontents. – egreg Nov 19 '12 at 17:24
hmm, but the first snippet of code I posted works as long as babel is not being used – justin.dong Nov 19 '12 at 17:29
It only "works" by accident. it would fail if \contentsname was used anywhere other than the main section title, for example page heading pdf bookmarks, ... – David Carlisle Nov 19 '12 at 17:31
I see. What is the proper way to modify the spacing only around the ToC title then? And add the horizontal line just below the title? – justin.dong Nov 19 '12 at 17:42

Here's a way; modify the spacings to suit you.

\makeatletter
\renewcommand{\tableofcontents}{%
\vspace*{-4mm}% reduce space before
\noindent{\Huge\contentsname\par}%
\vspace{2mm}% space between title and rule
\hrule
\vspace{2mm}% space below rule
\@starttoc{toc}}
\makeatother


Don't add formatting instructions to \contentsname, which should only contain the string to print.

-
Fantastic, thanks. This is exactly what I needed – justin.dong Nov 19 '12 at 18:02