Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
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 at 20:31
add comment

3 Answers 3

up vote 2 down vote accepted

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

share|improve this answer
    
Thank you friend .. your answer helped me a lot lol –  Freitas Feb 3 at 22:19
add comment

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

share|improve this answer
add comment

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 indentation before sectioning titles in the table of contents?.

share|improve this answer
    
Thanks for your help friend...worked lol –  Freitas Feb 3 at 22:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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