Page LayoutStar before Section Heading

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
Mendeleev
Posts: 4
Joined: Sat Jun 23, 2012 3:11 pm

Star before Section Heading

Post by Mendeleev »

Dear all,

I'm writing a book, and some of the sections in my chapters are optional.

In order to make this clear to the reader I would like to add a * in front of the number of those sections (both in the text, and in the contents). For example, I want to change

6.1.1 Historical prelude

to

*6.1.1 Historical prelude

Is there an easy way to do this, without affecting ALL the sections in my chapters ?

Thank you so much in advance !

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Star before Section Heading

Post by localghost »

Perhaps you can adapt a solution given in another topic [1]. In case of upcoming problems, feel free to ask further targeted questions.

[1] View topic: Place * (or other) at section number


Best regards and welcome to the board
Thorsten
Mendeleev
Posts: 4
Joined: Sat Jun 23, 2012 3:11 pm

Star before Section Heading

Post by Mendeleev »

Thank you a lot localghost! This already helped a lot!

I succeeded in placing a * in front of the section numbers, but still have some problems with the contents.

I am using the minitoc package to produce a mini table of contents at the start of my chapter. When I star a section, no star appears in the minitoc, but the dots connecting the title and page number disappear, and everything is shifted a little. For example:

6.1 Optional section ............................................................. 2
6.1.1 Subsection ................................................................... 4

becomes

6.1 Optional section 2
6.1.1 Subsection ................................................................... 4

I used the following texcode:

Code: Select all

\newcommand*{\secmark}{}
\newcommand*{\marktotoc}[1]{\renewcommand{\secmark}{#1}}
\newenvironment{optional}{
  \renewcommand*{\secmark}{*}
  \addtocontents{toc}{\protect\marktotoc{*}}
}{\addtocontents{toc}{\protect\marktotoc{}}}

\titleformat{\section}{\Large\bfseries}{\makebox[1.78em][l]{\secmark\thesection}}{0.5em}{}
\titleformat{\subsection}{\large\bfseries}{\makebox[2.56em][l]{\secmark\thesubsection}}{0.5em}{}
\titlecontents{section}[4em]{}{\bfseries\contentslabel[\secmark\thecontentslabel]{2.5em}}{\hspace*{1.5em}}{\titlerule*{}\bfseries\contentspage}
Any ideas ?
Last edited by Stefan Kottwitz on Sun Jun 24, 2012 10:33 am, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Star before Section Heading

Post by localghost »

Mendeleev wrote:[…] I am using the minitoc package to produce a mini table of contents at the start of my chapter. […]
Drop that package and use a similar feature of titletoc as described in Section 6.3 of its manual.
Mendeleev
Posts: 4
Joined: Sat Jun 23, 2012 3:11 pm

Re: Star before Section Heading

Post by Mendeleev »

Thanks. I'll give it a try ;-)
Post Reply