# Changing the section number to a fraction

In between two sections that really ought to be numbered 23 and 24, I want to add another section, which I would like to call 23.5. The code \setcounter{section}{23.5} \section{...}, however, results in a section labeled 24 with a .5 floating over the top of it. Is there a way around this?

-
Counters only accept natural numbers. Also, how would a reader distinguish between the fifth subsection of section 23 and section 23.5? – Caramdir Jan 8 '11 at 2:55
@Caramdir: That isn't quite true. Counters are simply a thin wrapper around a TeX count register. I.e., the counter foo is just a count register \c@foo defined by a \countdef. As such, it can be any integer in the range allowed by count registers. – TH. Jan 8 '11 at 8:22

A section between 23 and 24 seems to belong to 23 as well. Consider to use a main section 23 and split it into two subsections 23.1 and 23.2.

It would also be possible to write the section 23, then add a subsection 5 (\addtocounter{subsection}{4}\subsection{...}). Its number would be 23.5 then. If you wish, you could let a subsection appear like a section, just clone your titlesec commands.

-

Here's a hacky way:

\addtocounter{section}{-1}
\renewcommand{\thesection}{\arabic{section}.5}
\section{Title of Half section}
\renewcommand{\thesection}{\arabic{section}} % back to regular numbering


(But as Caramdir points out, this isn't really a great idea.)

-
What about replacing .5 by $\frac{1}{2}$ in your code? – Bruno Le Floch Jan 8 '11 at 5:16
@Bruno: well it would certainly solve Caramdir's problem. But it sure does look weird, especially when you add a subsection :-). – Alan Munn Jan 8 '11 at 5:43

The idea to do what you want is what Alan proposed, but if you want it to work properly with hyperref, you need to be a little more careful to avoid warnings like

pdfTeX warning
(ext4): destination with the same identifier (name{section.23}) has been already
used, duplicate ignored


which make hyperlinks to your half section point to the wrong place. To avoid this, you can define a master counter for sections and increment it just before the half section. Here's a full code showing how it works:

\documentclass{article}

\usepackage{hyperref}% must be before the definition of the mastercounter

% Master counter for sections
\newcounter{mastersection}
\makeatletter
\makeatother

\newcommand{\DontChangeNextSectionNumber}{%
% we save the old section number and substract one (\section does +1)
\edef\sectioncountervalue{\numexpr\the\value{section}-1\relax}%
% we increment the master counter
\refstepcounter{mastersection}%
% we set the section counter to the saved value
\setcounter{section}{\sectioncountervalue}%
}

\setcounter{section}{22}% for the numbers to start at 22 in this example

\begin{document}

\tableofcontents

\section{Title of section}

\DontChangeNextSectionNumber
\renewcommand{\thesection}{\arabic{section}\ensuremath{'}}
\section{Title of Half section}\label{half.section}

\subsection{Title of subsection}

\subsection{Title of subsection}

\renewcommand{\thesection}{\arabic{section}}
\section{Title of section}

\ref{half.section}

\end{document}


Instead of 23.5 or 23½, I've used 23’ which you see from times to times in some math books for theorem variants. If you don't like that, you can of course change it.

-
I must say I think that 23½ looks great. – Hendrik Vogt Jan 8 '11 at 13:39