# Adding unnumbered sections to TOC

I have many unnumbered sections in my report (more than 100), all created with:

\section*{section name}

I want to find a way to easily add them all to the TOC (specifically to a minitoc). Since I use the * to remove the numbering, they won't appear in TOC. I found out in minitoc documentation that I should use:

\addcontentsline{toc}{section}{repeat here section title}


However, I don't want to have a duplicated title in every section, or even to change all the involved files to add those already written sections to the TOC. How to add those sections' names to the minitoc without using the addcontentsline command? Is it possible?

The easiest way to do this is to use \section but to change secnumdepth so that they don't get numbered.

\documentclass{article}
\setcounter{secnumdepth}{0}
\begin{document}
\tableofcontents
\section{Foo}
\end{document}

• Thanks, it worked like a charm! It's easier to remove the * from each section than duplicate all their names! And I could even use the \setcounter{secnumdepth}{0} after some chapters, keeping the numbering on the previous ones! – Weslei Feb 21 '11 at 19:33
• A convenient solution, but unsuitable for documents with a mix of numbered and non-numbered parts. For these scenarios, look at @Vser 's answer below – Avision Dec 2 '17 at 8:40
• For a scoped version, enclose the relevant part in {} and use \makeatletter\c@secnumdepth=0\makeatother at the beginning.Also, to apply either to chapters, use -1. – golvok Aug 1 at 17:00

Another solution using \addcontentsline{toc}{section}{repeat here section title} relies on nameref. In fact I'm numbering every section (chapters and so on) with a label. So you could use:

\section*{Introduction}
\label{sec:intro}


It's only a local change and is persistent to names' change of your section.

• Do you need to include \usepackage{nameref} in the header to do this ? – usernumber Jun 29 '15 at 16:08
• Rather \usepackage{hyperref} I think. – lindhe May 23 '16 at 13:22
• This is a better solution for those seeking a document with both numbered and non-numbered parts/sections. – Avision Dec 2 '17 at 8:39

If you are using KOMA-Script the easiest way is to use these built in commands:

\addpart \addchap \addsec

Which work just like \part* \chapter* \section* while also being added to the toc.

What you can do is to redefine your chapters (or sections). Here I copy what I did for my report. I redefined \chapter* and defined a \chapter**

The latter is the old \chapter*, while the former is an unnembered chapter, but added to the toc.

 \let\@originalchapter\chapter
\def\chapter{
\@ifstar\chapterstar\@originalchapter
}
\def\chapterstar{
\@ifstar\chapter@nonum@notoc\chapter@nonum
}
\newcommand\chapter@nonum[2][]{
\ifthenelse{\isempty{#1}}{
\cleardoublepage
\phantomsection
\@originalchapter*{#2}
\chaptermark{#2}
}{
\cleardoublepage
\phantomsection
\@originalchapter*[#1]{#2}
\chaptermark{#1}
}
}
\newcommand\chapter@nonum@notoc[2][]{
\ifthenelse{\isempty{#1}}{
\@originalchapter*{#2}
\chaptermark{#2}
}{
\@originalchapter*[#1]{#2}
\chaptermark{#1}
}
}

\let\@originaltableofcontents\tableofcontents
\def\tableofcontents{
\let\@toclocaloriginalchapter\chapter
\def\chapter{\@toclocaloriginalchapter*}
\@originaltableofcontents
\def\chapter{\@toclocaloriginalchapter}
}

• Of course, you can do the same with \section and \section* – Oscar Jun 13 '17 at 17:51