Text Formattingnumbered section not in TOC

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
thomas
Posts: 7
Joined: Thu Jan 06, 2011 8:23 pm

numbered section not in TOC

Post by thomas »

Hello,

how can I avoid that a numbered section gets listed in the TOC?

What I already know:
\section{example} leads to a numbered new section which gets listed in the TOC.
\section*{example} leads to a new section which is not listed in the TOC but also gets no number. But I need a number for the section because I want to refer to the section.

Thanks in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

numbered section not in TOC

Post by frabjous »

It may depend on your document class and settings, but something like this might work well enough for the standard classes, for example:

Code: Select all

\section*{\refstepcounter{section}\thesection\quad Section Title}
might work well enough.
thomas
Posts: 7
Joined: Thu Jan 06, 2011 8:23 pm

Re: numbered section not in TOC

Post by thomas »

If I do it like that, the section gets numbered but not listed in the TOC. This is fine. But as I said I want to refer to the section:

\section*{\refstepcounter{section}\thesection\quad Section Title}\label{Section Title}

But in this case \ref{Section Title} does not refer to the correct section (let´s say A.1 in the appendix) but just to the chapter (i.e. A). How can I manage that the ref command refers to the correct section?
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

numbered section not in TOC

Post by frabjous »

Sorry. You have two choices. Either put the label inside the section* command:

Code: Select all

\section*{\refstepcounter{section}\label{mylabel}\thesection\quad Section Title}
Or move the \refstepcounter command outside of it (right before it).

Code: Select all

\refstepcounter{section}\section*{\thesection\quad Section Title}\label{mylabel}
If you're using hyperref, you may need to put a \phantomsection command before everything too to get the links working right.
thomas
Posts: 7
Joined: Thu Jan 06, 2011 8:23 pm

Re: numbered section not in TOC

Post by thomas »

I adopted the first proposal and it works very well. Thank you very much.

I modified it a bit (probably very dowdy). With your proposal the number of the section looks like 1.1 but because all other section numbers in my text have the form 1.1. I simply wrote

\section*{\refstepcounter{section}\label{mylabel}\thesection.\quad Section Title}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

numbered section not in TOC

Post by localghost »

Now that the problem is solved, please be so kind and mark the topic (not the last post) accordingly as clearly written in the Board Rules (to be read before posting). Please keep that in mind for the future so that further reminders will not be necessary.


Thorsten
Post Reply