Site icon texblog

Reverse numbering for chapters, sections, etc.

I was recently asked if there is a way to reverse the numbering of chapters in a report from n to 1. I didn’t find an easy way to do it which is why I decided to write a short post.

Here is the minimal example used to produce the above output. I will explain the details further below.

\documentclass[10pt]{report}
\usepackage{totcount}
\usepackage{blindtext}
\regtotcounter{chapter}
\makeatletter
	\renewcommand{\thechapter}{\number\numexpr\c@chapter@totc-\c@chapter+1\relax}
\makeatother

\begin{document}
\tableofcontents
\chapter{First Chapter}
	\Blindtext
\chapter{Second Chapter}
	\Blindtext
\chapter{Third Chapter}
	\Blindtext
\chapter{Fourth Chapter}
	\Blindtext
\end{document}

The code has to be typeset at least twice to get the numbers right.

 

Explanations of the code

First, the totcount package is loaded. It provides macros to print or use the total number (final value) of different counters. For some examples on how to use the package see here.

\usepackage{totcount}

Next, we need to tell the package which counter we want to use by registering it in the preamble.

\regtotcounter{chapter}

And finally we do the big math. We redefine the \thechapter macro, setting it to total number of chapters minus current chapter number plus 1. To evaluate the numerical expression we use \numexpr\relax.

\renewcommand{\thechapter}{\number\numexpr\c@chapter@totc-\c@chapter+1\relax}

 

Modifications for section

With a few minor changes, the code works for sections:

\documentclass[10pt]{article}
\usepackage{totcount}
\regtotcounter{section}
\makeatletter
	\renewcommand{\thesection}{\number\numexpr\c@section@totc-\c@section+1\relax}
\makeatother
\begin{document}
...

 

Reverse numbering for lists

For enumerate there exists a package, etaremune, providing macros to reverse the numbering. See this post for some examples.

Exit mobile version