5

When I hide a section with the asterisk it doesn't show the number in the heading and the section doesn't show up in the TOC.

How to hide a section but have the counter beeing added-up correctly so that \thesection gives the correct number of the section?

3
  • Do you use a documentclass which is provided by KOMA? Then you can use addchap or addsec Sep 30, 2011 at 11:23
  • \setcounter{section}{12} allows me to set the counter manually. But I'm looking for a more comfy way to only hide the number or even better allow me to place the number in the heading manually or leave it completly out.
    – Sebastian
    Sep 30, 2011 at 11:28
  • @Marco: I guess he likes to have the counter incremented even though the number isn’t displayed … and that’s not what \addchap does.
    – Tobi
    Sep 30, 2011 at 11:29

4 Answers 4

5

I don’ think there’s a finished macro/package for that but you can increment the counter either with \stepcounter{section} or with \refstepcounter{section} which increments the counter and updates the belonging \ref-lables.

So If you need a command for this try

\newcommand{\unnumsec}[1]{\refstepcounter{section}\section*{#1}}

or if you’re using KOMA-Script

\newcommand{\unnumsec}[1]{\refstepcounter{section}\addsec{#1}}

The main difference between \section* and \addsec is that the latter also sets the headmarks and generates a ToC entry, where \section* only prints text formatted like the section headline. (See the scrguien.pdf [or the german scrguide] for more information about \addsec command)

4

Adapting the answer from this question on stackoverflow:

Option 1 (use \section*, then \addtocounter to increment section counter):

enter image description here

\documentclass{article}

\begin{document}
\tableofcontents
\section{uno}
\section{dos}
\section*{hide}
\addtocounter{section}{1}
\section{tres}
\end{document}

Option 2 (suppress \addcontentsline temporarily):

enter image description here

\documentclass{article}

\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}

\begin{document}
\tableofcontents
\section{uno}
\section{dos}
\tocless\section{hide}
\section{tres}
\end{document}
1
  • 1
    I would need \numberless then..
    – Sebastian
    Sep 30, 2011 at 11:35
1

In your comment you say "even better allow me to place the number in the heading manually or leave it completly out".

That one's easy:

\renewcommand{\thesection}{}

The section counter gets incremented, but no number is displayed. (You still get the number in the TOC, though; not sure if you want that.)

1
  • No I want to place the section number individually in the section heading \section{This is \thesection . approach}. Not sure how this works.
    – Sebastian
    Oct 3, 2011 at 13:06
0

I use this redefined command to create sections without numbering but it keeps adding-up:

\newcommand{\sect}[1] {\section*{#1}\addcontentsline{toc}{section}{#1}\addtocounter{section}{1}}

Also in table of contents, of course.

1
  • Also you can change \addtocounter{section}{1} with \stepcounter{section} to better enumeration.
    – jfernandz
    Jul 5, 2016 at 11:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .