Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like sections in the table of contents to have not only the number, but also the symbol § before them. How can I make it?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

Here's one option using the tocloft package:

\documentclass{report}
\usepackage{tocloft}

\addtolength\cftsecnumwidth{0.7em} 
\renewcommand\cftsecpresnum{\S}

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{Test Section One}
\section{Test Section Two}
\section{Test Section Three}
\section{Test Section Fout}

\end{document}

enter image description here

share|improve this answer

Sections are special in the article document class and treated differently from subsections and lower-level sectional units in the ToC. As such, a patch (using etoolbox) of \l@section to insert § is sufficient:

enter image description here

\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}

The patch inserts \S before the first argument (#1) of \l@section. The first argument contains the number and name of the section.


For the report document class, the following patch does something similar, noting that sections at level 1:

enter image description here

\documentclass{report}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\@dottedtocline}% <cmd>
  {#4}% <search>
  {\ifnum#1=1\S\fi#4}% <replace>
  {}{}% <search><replace>
\makeatother
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{A section}
\end{document}
share|improve this answer
    
Thank you for your help! I'm using the report class for a small book and this patch doesn't work with it. Am I using sectioning wrong? –  Alvar Mar 16 '13 at 23:50
    
@HarishKumar Thank you, that worked! –  Alvar Mar 17 '13 at 0:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.