2

This is what I'm trying to do:

\renewcommand{\contentsname}{
\vspace{-8mm}
{\Huge Table of Contents}\vspace{-3mm}
\rule{\linewidth}{0.5mm} \\[-4mm]
}

Using babel, I can get this code to work:

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

\addto\captionsenglish{
  \renewcommand{\contentsname}
   %\vspace{10mm}
    {Table of Contents}
}

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

lockstep
  • 250,273
justin.dong
  • 1,249
  • \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
  • 2
    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

1 Answers1

4

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.

egreg
  • 1,121,712