Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Do you use a documentclass which is provided by KOMA? Then you can use addchap or addsec –  Marco Daniel Sep 30 '11 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 '11 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 '11 at 11:29

3 Answers 3

up vote 2 down vote accepted

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)

share|improve this answer

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}
share|improve this answer
    
I would need \numberless then.. –  Sebastian Sep 30 '11 at 11:35

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

share|improve this answer
    
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 '11 at 13:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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