[Tex/LaTex] Centering table of contents caption

table of contents

I would like to center the caption of my table of contents, so that it looks as follows:

                         Table of contents 

1.   Section                                              1
1.1  Subsection                                           3
1.2  Subsection                                           5
2    Section                                             11

Instead of

Table of contents 

1.   Section                                              1
1.1  Subsection                                           3
1.2  Subsection                                           5
2    Section                                             11

I've tried to \renewcommand{\contentsname}{\centerline{Table of contents}}, which worked fine for the apperance on the page.

But I'm using a book style where at the top of the page, on the left side, I want to have the name of the current chapter/section/whatsoever. But if I do the above, the text Table of contents is not on the left side, but in the middle (because of the \centerline).

Is there a way to accomplish what I want?

Best Answer

There are several package to modify the layout of contents. The simplest one for standard document classes may be tocloft. You can use:

\usepackage{tocloft}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill}

\tableofcontents is typesetted as \chapter*(for book and report) or \section*(for article). You can modify the layout of chapter(section) titles for table of contents. Thus sectsty or titlesec can be used for standard classes. You can use:

% \documentclass{article}
% \usepackage{sectsty}
\sectionfont{\centering}
\tableofcontents
\sectionfont{}

or

% \documentclass{article}
% \usepackage{titlesec}
\titleformat*{\section}{\centering\bfseries\Large}
\tableofcontents
\titleformat*{\section}{\bfseries\Large}

If you are using classes such as memoir and koma-script, there will be other command for this purpose. You'd better read the manual of these classes.