為什麼我的目錄重複這些部分?

為什麼我的目錄重複這些部分?
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}

\begin{document}

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

\end{document}

我正在嘗試建立一個目錄,但結果是這樣的

在此輸入影像描述

我只想顯示頂部部分,我不知道為什麼它會重複。另外,如何刪除標題左側的數字?如何設定每個部分和標題的頁碼?

答案1

除此之外,您的文件設定還受到指令使用不當\section以及\subsection產生分別標記為「章節」和「節」的標題的影響。為了減少不可避免的混亂,您可能需要切換到report文檔類,發出序言中的指令\setcounter{secnumdepth}{-1},並使用指令\chapter\section產生相應的標頭。

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

\begin{document}
\tableofcontents

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

如果您不想在目錄和第一個標題之間有分頁符,請改用以下程式碼:

\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}

相關內容