2

How to get section symbol § in front of subsection and subsubsection while i am using the code

\documentclass{article}  
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox  
\makeatletter
\patchcmd{\l@section}% <cmd>
  {#1}% <search>
  {\S#1}% <replace>
  {}{}% <search><replace>
\makeatother  
\begin{document}
\tableofcontents
\section{A section}
\end{document}

then i am just getting the symbol section for section not for subsection and subsubsection. Any of your help be mostly appreciated.

1
  • A quick hint: To have the site software pretty-print a code chunk, just highlight it and click on the {} "button" in the ribbon above the editor window.
    – Mico
    Commented Jun 20, 2020 at 4:15

1 Answer 1

1

You could extend your current approach to cover subsection- and subsubsection-level entries in the ToC:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@section}{#1}{\S#1}{}{}
\patchcmd{\l@subsection}{#1}{\S#1}{}{}
\patchcmd{\l@subsubsection}{#1}{\S#1}{}{}
\makeatother

However, I do not recommend that you go \patchcmd route, as it messes up the alignment of the entries in the ToC. Instead, I'd like to suggest that you employ the powerful machinery of the tocloft package.

enter image description here

\documentclass{article}  

\usepackage[titles]{tocloft}
\renewcommand\cftsecpresnum{\S} % see p. 10 of the package's user guide
\renewcommand\cftsubsecpresnum{\S}
\renewcommand\cftsubsubsecpresnum{\S}

\begin{document}
\tableofcontents
\section{A section}
\subsection{A subsection}
\subsubsection{A subsubsection}
\end{document}
1
  • 1
    Thanks a lot it works pretty good.
    – jhon
    Commented Jun 20, 2020 at 6:18

You must log in to answer this question.

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