Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to set a specific chapter or section number in LaTeX

📅 2012-Nov-30 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ chapter, counter, latex, numbering, section ⬩ 📚 Archive

Problem

LaTeX automatically numbers the chapters and sections that appear in a document. But sometimes it might be necessary to override the default numbering and assign a specific chapter or section number.

Solution

LaTeX maintains internal counters named as chapter and section that hold the chapter and section number. The value in the chapter counter is zero at the beginning of the document. The value in the section counter is zero at the beginning of every chapter. Every \chapter or \section command increments this counter.

So, a specific chapter or section number can be specified by manipulating the value inside this counter. The value in these counters can be set by using the \setcounter command.

For example, to have a chapter numbered 99 come right after chapter 1:

\chapter{First chapter}
%...
\setcounter{chapter}{98}
\chapter{Ninety-ninth chapter already}

The same technique can be used with section and subsection numbering to set specific numbers.

Tried with: MikTeX 2.9


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧