# How to display section number in the section's title?

Is there an easy way to display a section's number in its title? I am currently using the article document class.

Here is my minimal working example:

\documentclass[a4paper]{article}
\begin{document}

\section*{Introduction}

Introduction text here...

\section{Item 1: What is Quantitative Finance?}
Indeed, before actually studying a topic, we should start by having a good definition of what we are studying. So what is quantitative finance?

\section{Item 2: Geometric Brownian Motion}
blalblabla

\end{document}


By default the section numbers appear in front of the section's title. Instead I would like to have the section number appear inside the document's title after the word "Item" and be incremented automatically (so that I don't need to keep a manual count of the Item numbers).

• Only the sections ? Or \subsection etc as well?
– user31729
Jun 6, 2017 at 21:30
• I can have \subsection s but they will not be numbered. I only need the numbering at the section level after the word "Item" Jun 6, 2017 at 21:38

You mean something like this? Using titlesec will make automatically every section use the "Item xx" value.

\documentclass[a4paper]{article}
\usepackage{titlesec}
\titleformat{\section}[hang]{\bfseries}{Item \thesection:\ }{0pt}{}

\begin{document}

\section*{Introduction}

Introduction text here...

\section{What is Quantitative Finance?}
Indeed, before actually studying a topic, we should start by having a good definition of what we are studying. So what is quantitative finance?

\section{Geometric Brownian Motion}
blalblabla

\end{document}


• Yes this is exactly what I was looking for. Thanks! Jun 6, 2017 at 21:43

No package usage here, just slightly redefining \@seccntformat and checking with \pdfstrcmp whether it is section or another level.

\pdfstrcmp is a primitive provided by pdftex and pdflatex, so it is a built-in command.

\documentclass[a4paper]{article}

\makeatletter
\let\@seccntformatorig\@seccntformat
\def\@seccntformat#1{%
\ifnum0=\pdfstrcmp{#1}{section}%
Item \csname the#1\endcsname:{} %Well, could say Item \thesection:{} here as well...
\else
\@seccntformatorig{#1}%
\fi
}
\makeatother

\begin{document}

\section*{Introduction}

Introduction text here...

\section{What is Quantitative Finance?}
Indeed, before actually studying a topic, we should start by having a good definition of what we are studying. So what is quantitative finance?

\subsection{Foo}

\section{Geometric Brownian Motion}
blalblabla

\end{document}


No packages and the possibility of doing different things for different levels. Here I define \formatsection to add Item n: and \formatsubsection to do Subitem n.m:, whereas the standard output is used for \subsubsection.

\documentclass[a4paper]{article}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
\ifcsname format#1\endcsname
\csname format#1\endcsname
\else
\fi
}
\makeatother

\newcommand{\formatsection}{Item \thesection: }
\newcommand{\formatsubsection}{Subitem \thesubsection: } % just for example

\begin{document}

\section*{Introduction}

Introduction text here...

\section{What is Quantitative Finance?}

Indeed, before actually studying a topic, we should start by
having a good definition of what we are studying. So what is
quantitative finance?

\subsection{This is a subsection}

Here we have text.

\subsubsection{This is a subsubsection}

Here we have text.

\section{Geometric Brownian Motion}

blalblabla

\end{document}