2

I want to format both sections and subsections with a leading \S (section) symbol, but don't want subsections to appear in the TOC, so I wrote

\documentclass{article}
\usepackage{titlesec}

\setcounter{secnumdepth}{1}
\titleformat{\section}[hang]{\normalfont\Large\bfseries}{\S\ \thesection}{1em}{}
\titleformat{\subsection}[hang]{\normalfont\large\bfseries}{\S\ \thesubsection}{1em}{}

\begin{document}
\section{Section One}
\subsection{Subsection A}
\end{document}

This worked properly for the section, but the subsection got no leading symbol. The output was

enter image description here

If I remove the \setcounter{secnumdepth}{1}, everything works as expected (except of course for the TOC entries). I assume there's some way to tell titlesec what I want, but I can't figure it out.

0

1 Answer 1

2

You need to set the counter tocdepth, not secnumdepth.

\documentclass{article}
\usepackage{titlesec}

\setcounter{tocdepth}{1}
\titleformat{\section}[hang]{\normalfont\Large\bfseries}{\S\ \thesection}{1em}{}
\titleformat{\subsection}[hang]{\normalfont\large\bfseries}{\S\ \thesubsection}{1em}{}

\begin{document}
\tableofcontents
\section{Section One}
\subsection{Subsection A}
\end{document}

enter image description here

1
  • @rogerl You would not be the only one needing coffee. I knew packages like tocloft had a toc depth mechanism, but only stumbled across the fact that it is built into LaTeX directly. Commented May 25, 2017 at 15:40

You must log in to answer this question.

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