[Tex/LaTex] Add an asterisk in front of section label in TOC

table of contents

Could you please tell me how to make the table of content like this:

Preface…………………………….i

Chapitre 1. Les décisions …………….1

1.1 Bla bla bla ……………………6

1.2 Bla bla bla ……………………7

Chapitre 2. Les conférence ……………10

2.1 Bla bla bla ……………………16

*2.2 Bla bla bla ……………………17

2.3 Bla bla bla ……………………19

*2.4 Bla bla bla ……………………21

2.5 Bla bla bla ……………………25

Conclusion ………………………….30

Appendix A ………………………….35

Bibliographie ……………………….40

The section 2.2 and 2.4 prefix an asterisk to denote a hard level. The header mark is same as in TOC.

Best Answer

One way to do this is to create an environment that changes the format of the section number. Then a bit of tocloft magic will make the TOC entries look nice.

\documentclass{book}
\usepackage{tocloft}
\usepackage{lipsum} % for dummy text
\newenvironment{hard}
{\renewcommand{\thesection}{*\thechapter.\arabic{section}}}
{}
% set section numbers in TOC flush right (from the tocloft documentation)
\newlength{\extralen}
\setlength{\extralen}{0.5em}    % need some extra space at end of number
\renewcommand{\cftsecpresnum}{\hfill} % note the double ‘l’ 
\renewcommand{\cftsecaftersnum}{\hspace*{\extralen}}
\addtolength{\cftsecnumwidth}{\extralen}
\begin{document}
\tableofcontents
\chapter{A chapter}
\section{A regular section}\label{easylabel}
In Section~\ref{easylabel} we see\ldots
\lipsum
\begin{hard}
\section{A hard section}\label{hardlabel}
\lipsum
\end{hard}
In Section~\ref{hardlabel} we see\ldots
\end{document}

Note that this solution will also make the section number in references have an *, and subsections within a hard section will also bear an *. (For subsections you'll also need to add the appropriate tocloft code to make their numbers flush right as well.) If you don't want that, then things get a bit more compicated.

Table of contents from code