# Problems with titlesec for non-TOC subsections

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

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.

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}


• @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