[Tex/LaTex] Changing number format in ToC

formattingnumberingtable of contents

I'm using the tocloft package to alter the looks of my table of contents, but there's one thing I can't find in the documentation: splitting the number by level, to insert other delimiters than ".".

I'd like to have my ToC formatted in the following way:

1 § The First Section
     1 § 1. The First Subsection of the First Section
     1 § 1. The Second Subsection of the First Section
2 § The Second Section
etc…

To set the section level numbering, I use \renewcommand\cftsecaftersnum{ \S\ } which works like a charm. But I can't figure out how to get between the section and subsection counter on the subsection numbers.

For the record, numbers on the actual subsection headers are already using the desired format. It unfortunately does not carry over to the ToC…

Best Answer

If you redefine \thesubsection it would carry over to the TOC:

\renewcommand*{\thesubsection}{\thesection~\S~\arabic{subsection}}

Or start by adding it to \thesection:

\renewcommand*{\thesection}{\arabic{section}~\S}
\renewcommand*{\thesubsection}{\thesection~\arabic{subsection}}

Note, I used ~ instead of \ because a line break between number and § is not very desirable.