13

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

  • 1
    Can you provide us with some code in the form of a minimal working example (MWE)? ToCs are dependent on the packages that you're using to create sectional units, and also the type of \documentclass you're using. – Werner Feb 3 '14 at 20:31
10

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

13

Using the tocloft package, all you have to do is to set the indents to the same values: 0em (so entries are flushed to the left margin) and 2em (space to typeset the unit number). Using \cfttoctitlefont and \cftaftertoctitle you can center the title; I also set tocdepth to 2 since subsubsections are not to be listed according to the image:

\documentclass{article}
\usepackage{tocloft}

\cftsetindents{section}{0em}{2em}
\cftsetindents{subsection}{0em}{2em}

\renewcommand\cfttoctitlefont{\hfill\Large\bfseries}
\renewcommand\cftaftertoctitle{\hfill\mbox{}}

\setcounter{tocdepth}{2}

\begin{document}

\tableofcontents
\clearpage

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\section{Test section one}
\subsection{Test subsection}
\subsection{Test subsection}
\subsubsection{Test subsubsection}
\subsection{Test subsection}

\section{Test section two}
\subsection{Test subsection}
\subsection{Test subsection}
\subsubsection{Test subsubsection}
\subsection{Test subsection}

\end{document}

enter image description here

8

Here's a solution using titletoc package; it defines the dottedcontents command which has syntax:

% \dottedcontents{<section>}[<left>]{<above-code>}
% {<label width>}{<leader width>}

I have also used the command

\renewcommand{\contentsname}{\centering Contents}

to center the table of contents title.

screenshot

Here's the code:

% arara: pdflatex
% arara: pdflatex
\documentclass{article}
\usepackage{titletoc}

% \dottedcontents{<section>}[<left>]{<above-code>}
% {<label width>}{<leader width>}
\dottedcontents{section}[0em]{\bfseries}{2.9em}{1pc}
\dottedcontents{subsection}[0em]{}{3.3em}{1pc}

% center the toc heading
\renewcommand{\contentsname}{\centering Contents}

\begin{document}

\tableofcontents

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\section{Test section one}
\subsection{Test subsection}
\subsection{Test subsection}
\subsection{Test subsection}

\section{Test section two}
\subsection{Test subsection}
\subsection{Test subsection}
\subsection{Test subsection}

\end{document}

For further reading, see How to modify the space between the numbers and text of sectioning titles in the table of contents?.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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