[Tex/LaTex] formatting of the table of contents

formattingtable of contents

How can I change the settings of my table of contents, so that the sections and subsections are not indented as shown in the second picture. I would also like to center the title of the Contents. I am using the article class.

enter image description here

Best Answer

This is an approach which uses the »tocstyle« package with the tocflat option along with the standard style.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}

\usepackage[tocflat]{tocstyle}
\usetocstyle{standard}

\usepackage{blindtext}

% Redefinition of ToC command to get centered heading
\makeatletter
\renewcommand\tableofcontents{%
  \null\hfill\textbf{\Large\contentsname}\hfill\null\par
  \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}%
  \@starttoc{toc}%
}
\makeatother

\begin{document}
  \tableofcontents

  \blinddocument
\end{document}

You can compare with the tocfullflat option for equidistant spaces between numbers and heading entries. More details can be found in the package manual.

N.B.: You will get a warning about the alpha status of the package. So far is has not caused any major problems for me.


enter image description here

Related Question