In order to add the table of contents in your LaTeX document, just add the command \tableofcontents. Look at the below example to understand:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | \documentclass{article} \usepackage[utf8]{inputenc} \title{Learn LaTeX} \author{Anup Chaudhari} \date{ } \begin{document} \maketitle \tableofcontents \section{Introduction} This is the Introduction section. This tutorial teaches you how you can include the table of contents in any LaTeX document. \addcontentsline{toc}{section}{First Section} \section*{First Section} This is the First Section of the Tutorial. \section{Second Section} This is the Second Section of the Tutorial. \end{document} |
Generally, the table of contents includes chapters, sections, and subsection. You are also allowed to add entries manually in LaTeX. This is generally done to add the unnumbered sections. To do so, just add the \addcontentsline command, as shown in the above example.
Important Note: Remember in order to make sure that the table of contents works properly, you need to compile your LaTeX document twice.
Default title added when you use the table of contents is Contents. You can change the default title of the table of contents using \renewcommand*\contentsname{...} command. Let's understand with an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | \documentclass{article} \usepackage[utf8]{inputenc} \title{Learn LaTeX} \author{Anup Chaudhari} \date{ } \renewcommand*\contentsname{Tutorials} \begin{document} \maketitle \tableofcontents \section{Introduction} This is the Introduction section. This tutorial teaches you how you can include the table of contents in any LaTeX document. \addcontentsline{toc}{section}{First Section} \section*{First Section} This is the First Section of the Tutorial. \section{Second Section} This is the Second Section of the Tutorial. \end{document} |
The command \renewcommand*\contentsname{Leasons} will re-write/update the default value Contents with the new value Leasons.
Powered by www.resurchify.com