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.

I would like to suppress the typesetting of the section title in the document altogether, but still setting it for purposes of subsections, section mark / header, and table of contents.

What I tried already:

\section[MySection]{}

Still displays the section number.

\renewcommand{\thesection}{}
\section[MySection]{}

Removes the section number, but also removes it from subsection numbers and TOC. Besides, I still get a vertical space where the section title had been.

I could do (and have done so far):

\titleformat{\section}{}{}{0pt}{\vspace{-whatever_the_height_of_section_title}}

But it struck me as a bit ugly to "guess" the height of the section title (and having to re-guess if font sizes change). If there is some constant, like \sectionfontheight or somesuch, that would be a start.

But isn't there some "correct" way to set a section title "blindly", i.e. without actually printing it in the document?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted
\documentclass[a4paper]{article}
\newcommand{\nosection}[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \markright{#1}}

\begin{document}

\tableofcontents

\nosection{First}
\subsection{What?}

\nosection{Second}
\subsection{Right}

\end{document}

\refstepcounter sets the number and resets the subsection counter; \addcontentsline does its usual job; \markright sets the heading's contents.

share|improve this answer
    
Brilliant. It never occurred to me that I could approach the problem from the other direction (emulating everything \section does except the actual typesetting), instead of trying to suppress the typesetting of \section. Replacing \arabic{section} (section number w/o chapter) with \thesection (chapter.section) made it fit my needs 100%. Thank you - It would've probably taken me ages to figure out the \addcontentsline myself, even if the basic idea had struck. –  DevSolar Sep 23 '11 at 10:04
add comment

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.