Basic Syntax Create your first LaTeX Title Section Paragraph and Comments Text Processing Fonts Formatting List
Document type in Latex↓
Document Class Document Classes Comparison Document Classes Options
Command Table of Contents Page Numbering Footnotes Language Support
Bibliography ↓
Bibliography Management With Biblatex Bibliography Management With Natbib
Table of contents

Autogenerate table
Creating the table of contents is quite simple, using only a few commands:

CODE
\documentclass{article}

\begin{document}

\tableofcontents

\section{Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\subsection{Subsection}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\end{document}
List of figures/tables
A list of figures or tables works in the same way:

CODE
\documentclass{article}

\begin{document}

\begin{appendix}
\listoffigures
\listoftables
\end{appendix}

\begin{figure}
\caption{Figure example}
\end{figure}

\begin{table}
\caption{Table example}
\end{table}

\end{document}
Depth
The depth of the table of contents can be manually modified using the command \setcounter{tocdepth}{X}, where X is the desired depth. If X is 0, then the table of content will not be shown. If it is 3, then even subparagraphs will be shown. The value needs to be set in the preamble of the document so that it automatically applies to the whole document.

Setting X as 1 will give the following output:

CODE
\documentclass{article}

\setcounter{tocdepth}{1}

\begin{document}

\tableofcontents
\section{Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\subsection{Subsection}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\end{document}

Increasing the number, e.g. setting X as 4, will give the following output:

CODE
\documentclass{article}

\setcounter{tocdepth}{4}

\begin{document}

\tableofcontents
\section{Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\subsection{Subsection}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\paragraph{Paragraph}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\end{document}
Spacing
The easiest way to change the spacing of the table of contents is by using the setspace package. It needs to be added to your preamble with the \usepackage{setspace} command. Then, you can set the spacing for individual parts of your document like this:

CODE
\documentclass{article}

\setcounter{tocdepth}{2}
\usepackage{setspace}

\begin{document}

\doublespacing
\tableofcontents
\singlespacing

\section{Section}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\subsection{Subsection}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortisfacilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\section{Section two}

Lorem ipsum dolor sit amet...

\subsection{Subsection two}

Lorem ipsum dolor sit amet...

\end{document}