1

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.

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

  • @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. – Steven B. Segletes May 25 '17 at 15:40

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.