# Section title formatting

In the book I translate, some sections are optional and this is denoted by a star before section number .... for example, Section 3.5 with the Title A is not optional but Section 3.6 with the Title B is optional .. this gives the results

3.5 Title A and
*3.6 Title B


How can put a star before section number and how i can remove from the next (not optional) sections?

• You should take a look at the documentation of titlesec, §4.3 Variants. – Bernard Mar 19 '18 at 14:21

As @Bernard commented this is possible with the titlesec package. However, it is also easy to do without packages, which might be preferred if you don't want to use titlesec for some reason.

MWE:

\documentclass{book}
\newcommand{\optionalsection}[1]{%
\renewcommand\thesection{*\arabic{chapter}.\arabic{section}}%
\section{#1}%
\renewcommand\thesection{\arabic{chapter}.\arabic{section}}%
}
\begin{document}
\chapter{First chapter}
\section{First section}
\optionalsection{Optional section}
\section{Third section}
\end{document}


Here a new command called \optionalsection is defined that first changes the section number format to a *, the chapter number, a dot, and the section number, then creates a section with this format, then resets the section number to the default format.

Result:

• Perhaps it would look nicer to code \renewcommand\thesection{\llap{*}\arabic{chapter}.\arabic{section}}%: the chapter number would till be at the left margin, and the star would be protruding into the left margin. – Bernard Mar 19 '18 at 17:32