How to make chapter*, section* and subsection* appear in the table of contents
I don't think an specialized command exists for that. But you can use
\addcontentsline{toc}{chapter}{#1}
to add it to the TOC. BTW, I didn't have problems with \chapter* and fancy, so I used:
\newcommand\chap[1]{%
\chapter*{#1}%
\addcontentsline{toc}{chapter}{#1}}
Variations on this question have been asked and answered several times on the TeX-specific sister site:
- Creating unnumbered chapters/sections (plus adding them to the ToC and/or header)
\tableofcontents
does not list the unnumbered chapter- How to use
\section*{something}
without removing it from the Table of Contents? - Redefine
\section*
so it behaves exactly as\section
except leaves out the number - ...
I'm going to copy over Werner's answer to the last of those, because it demonstrates a different technique from any of the existing answers to this question: redefine \section
so that the only effect of \section*
is to skip printing the section numbers. This will work even when sectioning commands are being issued from the guts of packages you don't control.
[...] Redefine \section
to capture and condition on when the starred-version is used. Upon finding \section*
, issue it just like you would \section
, but remove the number-printing mechanism through an appropriate setting of the counter secnumdepth
.
xparse
provides an easy interface for (re)defining commands that may have a s
tarred version, as well as an o
ptional argument.
\usepackage{xparse}
\let\oldsection\section
\makeatletter
\newcounter{@secnumdepth}
\RenewDocumentCommand{\section}{s o m}{%
\IfBooleanTF{#1}
{\setcounter{@secnumdepth}{\value{secnumdepth}}% Store secnumdepth
\setcounter{secnumdepth}{0}% Print only up to \chapter numbers
\oldsection{#3}% \section*
\setcounter{secnumdepth}{\value{@secnumdepth}}}% Restore secnumdepth
{\IfValueTF{#2}% \section
{\oldsection[#2]{#3}}% \section[.]{..}
{\oldsection{#3}}}% \section{..}
}
\makeatother
(To do the same thing to \chapter
, \subsection
, etc., search-and-replace section
appropriately, and adjust the temporary value used for secnumdepth
.)