[Tex/LaTex] Why the table of contents duplicate the sections

syntaxtable of contents

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}

\begin{document}

\tableofcontents
\section{Chapter 5}
\subsection{Section 1}

\end{document}

I am trying to create a table of contents but it comes out like this

enter image description here

I only want the top part to display, I don't know why it's duplicating. Also, how can I delete the numbers on the left side of the titles? And how can I set up the page number for each section and title?

Best Answer

Among other things, your document setup suffers from mis-using of the directives \section and \subsection to generate headers that are labeled "chapter" and "section", respectively. To reduce the confusion that will inevitably follow, you may want to switch to the report document class, issue the instruction \setcounter{secnumdepth}{-1} in the preamble, and use the directives \chapter and \section to generate the corresponding headers.

\documentclass{report} % not 'article'
\setcounter{secnumdepth}{-1}

\begin{document}
\tableofcontents

\chapter{Chapter 5}
\section{Section 1}
\end{document}

If you do not want to have a page break between the table of contents and the first header, use the following code instead:

\documentclass{report} % not 'article'
\setcounter{secnumdepth}{-1}

\begin{document}
\tableofcontents

\begingroup
\let\clearpage\relax % locally disable '\clearpage'
\chapter{Chapter 5}
\endgroup
\section{Section 1}
\end{document}
Related Question