4

I was wondering about the inverse of this question:

Hiding section titles when the section is empty

Instead of hiding empty sections in LaTeX, can one display only empty sections or somehow indicate that a section is empty in the table of contents?

2

2 Answers 2

4

This comes as first idea:

\documentclass{article}
\usepackage{etoolbox}
\newcommand{\emphsection}[2]{% emhasizes empty sections
    \ifstrequal{ #2}{ }{\section[empty: #1]{#1} #2}{\section{#1} #2}%
}

\begin{document}
\emphsection{Emptysection}{}
\emphsection{Section 1}{%
This section won't be emphasized
}
\emphsection{Section 2}
Neither this one.
\tableofcontents
\end{document}
11
  • This works, thank you! (Just to clarify for others reading this: Argument #1 = section title, Argument #2 = section text.) Sep 16, 2013 at 15:37
  • @AnthonyPulido This works, but there are some costs to making the section text an argument, notably that verbatim won't work any more, it's also slower although that is less important these days. Sep 16, 2013 at 16:18
  • @DavidCarlisle Yes, I think you're right. I spoke too soon. I tried it on a small bit of text at first, which worked. I then tried it on what I wanted to use it on, text with subsections and long paragraphs. I'm now receiving an error: TeX capacity exceeded, sorry [input stack size=5000]. Sep 16, 2013 at 16:38
  • @Crowley Would you have any new ideas? Sep 16, 2013 at 16:39
  • 1
    @AnthonyPulido you can always omit the {} around a tex parameter, so if you omit the {} in this case the the argument is the first letter or command of the section, although in most cases that will work OK. Sep 17, 2013 at 18:59
0

Perhaps this would work

\section*{}

This will create a new blank section with the same spacing as a normal section.

New contributor
user277741 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • I needed to be able to tell which sections were blank from looking at the table of contents, and so this is not quite what I was looking for, but thank you! Aug 5 at 18:38

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.