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.
3 Answers
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.
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}
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.
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?.
\documentclass
you're using.