61

Is it possible just to generate a table of contents based on sections in asterisk mode, i.e., \section*? I basically just want the table of contents without section numbers. Like a list of headings and their associated pages.

The following doesn't generate a ToC:

\documentclass[12pt,a4paper]{article}

\begin{document}

\tableofcontents

\subsection*{Section 1}

\subsection*{Section 2}

\end{document}

4 Answers 4

62

You don't have numbered sections, do you? In this case the simplest arrangement is

\setcounter{secnumdepth}{0} % sections are level 1

\begin{document}

\section{First}

\section{Second}

No sectional unit below \section will be numbered, but sections and subsections will go anyway in the table of contents (as this depends on the value of the tocdepth counter, default 2).

12
  • 1
    Suppose I don't want numbering for headings at any level, how would I modify your solution? Keep in mind I do still want a table of contents, just without heading numbering...
    – ptrcao
    Oct 2, 2011 at 12:40
  • 15
    \setcounter{secnumdepth}{-2} will remove the numbering also for parts (and all levels below).
    – egreg
    Oct 2, 2011 at 12:41
  • 1
    This is a good solution - very minimal and unobtrusive, without any compromise. :)
    – ptrcao
    Oct 3, 2011 at 10:03
  • 1
    For some reason this is not working for me. I still get the numbered sections and subsections. Could it be due to the fact that I use a template and a master file including chapter files? Do I have to insert \setcounter{secnumdepth}{0} in a special place? Jan 22, 2014 at 18:26
  • 2
    @FrankEjbyPoulsen Try just after \begin{document}
    – egreg
    Jan 22, 2014 at 20:56
53

The following is a manual way of adding entries to the table of contents by means of \addcontentsline:

\documentclass[12pt,a4paper]{article}

\begin{document}

\tableofcontents

\section*{Section 1}
\addcontentsline{toc}{section}{\protect\numberline{}Section 1}%
\section*{Section 2}
\addcontentsline{toc}{section}{\protect\numberline{}Section 2}%

\end{document}

Starred sections in ToC

The reason for using \numberline{} is to allow for the traditional numbered space in the table of contents. If you're not interested in this numeric alignment, then you can drop the \protect\numberline{}.

1
  • 4
    Thanks! The advantage of this approach is that it allows combining sections and section*s in a straightforward manner
    – Wouter
    Jun 5, 2020 at 15:15
8

Adapting DevSolar's answer from this question (clearing out the definition of \thesection), and assuming you don't really care if you use \section*, you just want to remove numbers from the headings and ToC entries:

enter image description here

\documentclass[12pt,a4paper]{article}
\renewcommand{\thesection}{}
\begin{document}
\tableofcontents
\section{A Section}
\section{Another Section}
\end{document}
4
  • Thanks Mike - this seems like a fairly succinct solution - and moreover it works, though would you mind explaining what is happening? I don't understand why/how this works.
    – ptrcao
    Oct 2, 2011 at 4:37
  • 4
    In many cases, \theX is a macro that prints the number of the current document division (where 'X' is chapter, section, subsection, etc.) Clearing it out prevents it from being printed. However, on further examination, this doesn't suppress the space between the number and the division title, and the section headings get indented more than I'd like. So I'd go with egreg's version instead. Oct 3, 2011 at 3:23
  • This is a nice option. However, in my case, it leaves a blank space where there was supposed to be the number of the section, subsection etc. How do I get rid of that? Jan 22, 2014 at 17:54
  • As I'd indicated, I'd go with egreg's solution over mine. Jan 23, 2014 at 17:52
1

what about using

\addsec{}

instead of

\section*{}

2
  • 8
    Welcome to TeX.SX! Can you extend your answer a bit to explain what is the difference between the two commands? Also, the OP uses the article class, and I think \addsec is only available in the KOMA classes.
    – Tiuri
    Nov 17, 2019 at 15:23
  • 1
    With the added info that \addsec needs a KOMA script class and ideally a short example document demonstrating its use and effects (based on the MWE in the question) this could be a great answer.
    – moewe
    Nov 17, 2019 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.