Mark up your document with commands like \section and \chapter, and LaTeX takes care of the heading style, the numbering, and the table of contents for you. This page walks through the heading hierarchy, how numbering works and how to control it, switching into appendices and book matter, and building the table of contents.
The sectioning hierarchy
You create a heading with a single command. Writing \section{Introduction}, for example, sets a numbered section heading like “1 Introduction” in the typeface and spacing the class defines. Headings form a hierarchy of levels: from the top down, \part, \chapter, \section, \subsection, \subsubsection, \paragraph, and \subparagraph — seven rungs. Each level carries an integer level number, and that number is the basis for the numbering- and TOC-depth controls we meet below.
One important caveat: \chapter exists **only in the book and report classes**. The article class has no notion of a chapter, so the top-level heading in an article is normally \section. \part is available in every class, but it sits at level 0 in article and at level −1 — above \chapter — in book and report.
| Command | Level | Unit | Available in |
|---|---|---|---|
\part | −1 (book/report), 0 (article) | Part | All classes |
\chapter | 0 | Chapter | book / report only |
\section | 1 | Section | All classes |
\subsection | 2 | Subsection | All classes |
\subsubsection | 3 | Subsubsection | All classes |
\paragraph | 4 | Run-in heading (flows into the text) | All classes |
\subparagraph | 5 | Run-in subheading (flows into the text) | All classes |
From \part down to \subsubsection you get a heading on its own line, but \paragraph and \subparagraph behave differently: they are run-in headings, with no line break after them — the body text continues on the same line. Reach for them when you want a short label at the head of a paragraph.
\documentclass{report} % \chapter が使える
\begin{document}
\chapter{序論}
\section{背景}
\subsection{先行研究}
\paragraph{要点}\ ここから本文が続きます。
\end{document}Controlling the numbering
LaTeX numbers headings automatically. How deep that numbering goes is governed by the **secnumdepth** counter, which holds the level number of the deepest unit that gets a number. With secnumdepth at 1, for instance, \section (level 1) is numbered but \subsection (level 2) and anything below it appears without a number. The defaults are **3 in article and 2 in book/report**; change it in the preamble with \setcounter{secnumdepth}{3} (the usual move when you want subsubsections numbered in book).
To drop the number from a single heading, use the starred form of the command. Writing \section*{Acknowledgements} with a * produces a heading that carries no number and does not appear in the table of contents. It is the standard choice for headings that read oddly with a number — “Introduction,” “Acknowledgements,” “Conclusion,” and the like.
The other thing worth knowing is the optional argument. Writing \section[Short title for the TOC]{Long title shown in the body} puts the long form in the body heading and the short bracketed form in the table of contents and running heads. It is handy for keeping a long heading compact in the contents.
\setcounter{secnumdepth}{3} % 小々節まで番号を付ける
\section{結果と考察} % 番号付き:例「3 結果と考察」
\section*{謝辞} % 番号なし・目次にも出ない
\section[手法]{提案手法の詳細な定式化} % 目次には「手法」と出るAppendices and front / main / back matter
To set appendices after the body, write **\appendix once at the point where the appendices begin. It is not a heading command but a switch that changes the numbering**: from there on the chapter and section counters reset and their display turns into the letters A, B, C, and so on. After \appendix you just write the appendix headings with \chapter or \section as usual.
The book class has dedicated commands for splitting a book into three parts. **\frontmatter opens the front matter (preface, contents, and so on): it numbers pages in lowercase roman numerals (i, ii, …) and leaves chapters unnumbered, though their titles still appear in the table of contents. \mainmatter begins the body, switching page numbers back to arabic and resetting them to 1, with chapter numbers restored. \backmatter** marks the back matter (bibliography, index): it leaves the page numbering running on and, once more, stops numbering chapters.
\documentclass{book}
\begin{document}
\frontmatter % i, ii, … 章は番号なし
\tableofcontents
\mainmatter % 1, 2, … 章を番号付きで
\chapter{序論}
\appendix % 以降の章は A, B, …
\chapter{記号一覧}
\backmatter % 参考文献・索引など
\end{document}Building the table of contents
A table of contents is generated simply by placing **\tableofcontents**. Here is how it works: while processing, LaTeX writes each heading’s information to an auxiliary .toc file, then reads that file back on the next run to typeset the contents. Because of this you must compile at least twice to get a correct table of contents (on the first run the contents are still empty or out of date). A build tool such as latexmk repeats the runs for you automatically.
How deep the contents go is set by the **tocdepth** counter. Its meaning mirrors secnumdepth: the level number of the deepest unit listed in the contents. With \setcounter{tocdepth}{1}, for example, the contents include \section (level 1) but omit \subsection (level 2) and below. The defaults are again **3 in article and 2 in book/report**. Note that the numbering depth (secnumdepth) and the contents depth (tocdepth) are set independently.
You can build lists of figures and tables the same way. **\listoffigures produces a list of figures and \listoftables** a list of tables, using the auxiliary files .lof and .lot respectively (and likewise needing more than one compilation).
To add an entry to the contents by hand — for an item that is not listed automatically, such as a starred heading — use **\addcontentsline{ext}{unit}{text}**. The first argument ext is the target file extension (toc for the contents, lof for the list of figures, lot for the list of tables); the second, unit, is the kind of entry (section, chapter, figure, …); the third, text, is the string to list. To insert arbitrary, non-line material (such as extra spacing), use **\addtocontents{ext}{text}** instead.
\tableofcontents
\setcounter{tocdepth}{2} % 小節まで目次に載せる
\section*{はじめに} % 星付きは自動では載らない
\addcontentsline{toc}{section}{はじめに} % 手動で目次に追加
\listoffigures % 図目次
\addtocontents{lof}{\protect\vspace{2ex}} % 図目次に空きを差し込む