1

Is there an easy way to use numbering for subsections in the TOC, but to hide the subsection numbers in the document body?

I could use \subsection*{Title} but then the entries are gone from the TOC.

  • 2
    Does it make sense? I mean, what's the purpose of a number in the TOC when the number doesn't really exist? – egreg Dec 3 '13 at 17:28
  • The TOC looks nicer with the numbers, the hierarchy is clearer. But in the body itself, it can be distracting when there are many, but short subsections. – Danilo Bargen Dec 3 '13 at 17:35
  • @DaniloBargen You run the risk of confusing your reader, though. Proceed with caution. – jub0bs Dec 3 '13 at 18:16
3

Assuming that you have a good reason to do that, here's how you can do.

Put, just after each unnumbered subsection, the lines

\stepcounter{subsection}
\addcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}<name>}

where <name> is the name of the subsection.

Note that I've used \stepcounter instead of \refstepcounter voluntarily, hoping you don't have to reference these subsections...

MWE:

\documentclass{article}

\usepackage{lipsum}

\begin{document}

\tableofcontents

\section{Testing subsections}

\subsection*{First unnumbered subsection}
\stepcounter{subsection}
\addcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}First unnumbered subsection}
\lipsum[1-2]

\subsection{Numbered subsection}
\lipsum[1]

\subsection*{Second unnumbered subsection}
\stepcounter{subsection}
\addcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}Second unnumbered subsection}
\lipsum[1]

\end{document} 

Output:

enter image description here

| improve this answer | |

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.