Text Formatting ⇒ Place * (or other) at section number
Place * (or other) at section number
Some of my sections are optional for reading so I would like to place an *
at the corresponding number of the section title, i.e. something like
*12-5 Double slit experiment
Is there any straightforward way to achieve this or should I override a variable or two?
at the corresponding number of the section title, i.e. something like
*12-5 Double slit experiment
Is there any straightforward way to achieve this or should I override a variable or two?
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Posts: 87
- Joined: Tue Sep 14, 2010 6:58 pm
Place * (or other) at section number
If all you want is the symbol itself, then where ever you want it to appear, you can use:
Code: Select all
\textasteriskcentered
Re: Place * (or other) at section number
Unfortunately this doesn't work.
As I said I want the symbol (* in my case) to be placed in front of the section number. Like
*12-1 This is a section title
As I said I want the symbol (* in my case) to be placed in front of the section number. Like
*12-1 This is a section title
-
- Posts: 87
- Joined: Tue Sep 14, 2010 6:58 pm
Re: Place * (or other) at section number
Are you using the article class? Memoir? Do you have an MWE?
-
- Posts: 87
- Joined: Tue Sep 14, 2010 6:58 pm
Place * (or other) at section number
Tacky, but this works as a temporary fix.
Code: Select all
\documentclass{article}
\newcommand{\starsection}[1]{\addtocounter{section}{1}%
\addcontentsline{toc}{section}{*\thesection\hspace{1em}#1}%
{\vspace{1.5em}\par\noindent\bfseries\Large *\thesection\hspace{0.5em} #1}\par\vspace{1em}\noindent}
\begin{document}
\tableofcontents
\section{First section}
Some text.
\subsection{subsection}
Text goes here.
\starsection{Second section}
This is text.
\subsection{second subsection}
More text.
\section{Third section}
This is more text.
\subsection{third subsection}
How do you do?
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Place * (or other) at section number
Straightforward, no. Possible, yes. The titlesec/titletoc manual introduces a method that allows to tag the concerned section(s) in the document as well as in the ToC (Section 7.7 — Marking entries with asterisks, p. 22). Due to a missing minimal example I derived an example for the »article« class (because you talked of sections).yiorgosb wrote:Some of my sections are optional for reading so I would like to place an * at the corresponding number of the section title […] Is there any straightforward way to achieve this or should I override a variable or two?
Code: Select all
\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{titletoc}
\usepackage{blindtext}
\title{A document with stuff for advanced reading}
\author{yiorgosb}
\newcommand*{\secmark}{}
\newcommand*{\marktotoc}[1]{\renewcommand{\secmark}{#1}}
\newenvironment{advanced}{
\renewcommand*{\secmark}{*}%
\addtocontents{toc}{\protect\marktotoc{*}}
}{\addtocontents{toc}{\protect\marktotoc{}}}
\titleformat{\section}{\normalfont\Large\bfseries}{\makebox[1.5em][l]{\secmark\thesection}}{0.4em}{}
\titlecontents{section}[1.5em]{}{\bfseries\contentslabel[\secmark\thecontentslabel]{1.5em}}{\hspace*{-1.5em}}{\titlerule*{}\bfseries\contentspage}
\newpagestyle{front}{%
\headrule
\sethead[\thepage][][\subsectiontitle]{\sectiontitle}{}{\thepage}
\setfoot[][][]{}{}{}
}
\newpagestyle{main}{%
\headrule
\sethead[\thepage][][\thesubsection\quad\subsectiontitle]{\thesection\quad\sectiontitle}{}{\thepage}
\setfoot[][][]{}{}{}
}
\newpagestyle{back}{%
\headrule
\sethead[\thepage][][\thesubsection\quad\subsectiontitle]{\thesection\quad\sectiontitle}{}{\thepage}
\setfoot[][][]{}{}{}
}
\begin{document}
\pagestyle{front}
\maketitle
\tableofcontents\newpage
\pagestyle{main}
\blinddocument
\blinddocument
\begin{advanced}
\blinddocument
\end{advanced}
\appendix
\pagestyle{back}
\blinddocument
\end{document}
As always, the blindtext package is only for creating dummy text thus not part of the actual solution.
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Place * (or other) at section number
Thank you for your reply.
The suggested solution works like a charm.
However, since my sections are large it is cumbersome to follow
the \begin{advanced}...\end{advanced} environment.
Is it possible to define it as a newcommand?
A note for any future reader:
As I found by trial and error the definition:
in required for the mark (*) to appear.
The suggested solution works like a charm.
However, since my sections are large it is cumbersome to follow
the \begin{advanced}...\end{advanced} environment.
Is it possible to define it as a newcommand?
A note for any future reader:
As I found by trial and error the definition:
Code: Select all
\titleformat{\section}{\normalfont\Large\bfseries}{\makebox[1.5em][l]{\secmark\thesection}}{0.4em}{}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Place * (or other) at section number
I see two possible solutions.yiorgosb wrote:[…] However, since my sections are large it is cumbersome to follow the \begin{advanced}...\end{advanced} environment. Is it possible to define it as a newcommand? […]
- Split your document by swapping the sections to external files with one single section each. Then you could use the \include or \input command inside the new »advanced« environment without losing track of the marked sections.
- Replace the definition of the »advanced« environment with the definition of two new commands which serve as switches (see code below). They will turn the asterisks on or off. Just put them right before a section wherever you need them.
Code: Select all
\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{titletoc}
\usepackage{blindtext}
\title{A document with stuff for advanced reading}
\author{yiorgosb}
\newcommand*{\secmark}{}
\newcommand*{\marktotoc}[1]{\renewcommand{\secmark}{#1}}
\newcommand*{\advanced}{%
\renewcommand*{\secmark}{*}%
\addtocontents{toc}{\protect\marktotoc{*}}%
}
\newcommand*{\basic}{%
\renewcommand*{\secmark}{}%
\addtocontents{toc}{\protect\marktotoc{}}%
}
\titleformat{\section}{\normalfont\Large\bfseries}{\makebox[1.5em][l]{\secmark\thesection}}{0.4em}{}
\titlecontents{section}[1.5em]{}{\bfseries\contentslabel[\secmark\thecontentslabel]{1.5em}}{\hspace*{-1.5em}}{\titlerule*{}\bfseries\contentspage}
\newpagestyle{front}{%
\headrule
\sethead[\thepage][][\subsectiontitle]{\sectiontitle}{}{\thepage}
\setfoot[][][]{}{}{}
}
\newpagestyle{main}{%
\headrule
\sethead[\thepage][][\thesubsection\quad\subsectiontitle]{\thesection\quad\sectiontitle}{}{\thepage}
\setfoot[][][]{}{}{}
}
\newpagestyle{back}{%
\headrule
\sethead[\thepage][][\thesubsection\quad\subsectiontitle]{\thesection\quad\sectiontitle}{}{\thepage}
\setfoot[][][]{}{}{}
}
\begin{document}
\pagestyle{front}
\maketitle
\tableofcontents\newpage
\pagestyle{main}
\blinddocument
\advanced
\blinddocument
\basic
\blinddocument
\appendix
\pagestyle{back}
\blinddocument
\end{document}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Place * (or other) at section number
Thank your for your reply.localghost wrote: I see two possible solutions.
When I was asking for a command what I had in mind was something like
\newcommand{\advsection}{some definitions here}
which would define the new advanced section.
Then the usage of this command to text would be
Code: Select all
\documentclass[11pt,a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{titletoc}
\usepackage{blindtext}
\newcommand{\advsection}{some definitions here}
\begin{document}
\section{Normal section}
\blindtext
\advsection{Advanced section}
\blindtext
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Place * (or other) at section number
If the stuff I provided is not satisfactory, you should take a look at the code example that west.logan provided earlier. I contributed my share to solve this problem.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10