48

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}
| improve this question | | | | |
50

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).

| improve this answer | | | | |
  • 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 '11 at 12:40
  • 13
    \setcounter{secnumdepth}{-2} will remove the numbering also for parts (and all levels below). – egreg Oct 2 '11 at 12:41
  • 1
    This is a good solution - very minimal and unobtrusive, without any compromise. :) – ptrcao Oct 3 '11 at 10:03
  • You are a hero. Take my internet points. – Henrik Jun 29 '13 at 12:46
  • 1
    @FrankEjbyPoulsen Try just after \begin{document} – egreg Jan 22 '14 at 20:56
37

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{}.

| improve this answer | | | | |
6

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}
| improve this answer | | | | |
  • 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 '11 at 4:37
  • 3
    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. – Mike Renfro Oct 3 '11 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? – Frank Ejby Poulsen Jan 22 '14 at 17:54
  • As I'd indicated, I'd go with egreg's solution over mine. – Mike Renfro Jan 23 '14 at 17:52
0

what about using

\addsec{}

instead of

\section*{}

| improve this answer | | | | |
  • 5
    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 '19 at 15:23
  • 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 '19 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.