# How to number everything (sections, pages, figures, list items etc) starting at zero?

Like Dijkstra, I believe one should count things starting at zero. How do I achieve zero-based numbering throughout in LaTeX for chapters, sections, figures, tables, pages, references, footnotes, equations, list items, lines, and whatever else there may be?

I'm using the memoir documentclass.

• Use \setcounter{chapter}{-1} Commented Nov 1, 2014 at 13:50
• I think you're reading Dijkstra in the wrong way. The chapter number is zero until a chapter starts, so it must be number 1. Another instance when numbering from 1 is right: when I talk about the sequence of vectors $\{v_1;v_2;\dots;v_n\}$ I'm not excluding $n=0$, in which case the sequence is empty; $n$ denotes exactly the number of vectors in the sequence. Commented Nov 1, 2014 at 14:54
• @egreg it's over use of C it addles the mind:-) Commented Nov 1, 2014 at 14:58
• @egreg I'm pretty sure Dijkstra means that the lowest-numbered element should have number zero. That's how he numbers his pages in the note I linked to, for instance, and he gives "0 ≤ i < N" as an example of a good subscript range. In any case, that's how I want to do it. Commented Nov 1, 2014 at 22:57
• @jolson And my example shows he's, with due respect, wrong. Commented Nov 1, 2014 at 23:06

\documentclass{article}

\makeatletter
\def\@arabic#1{\number\numexpr#1-1\relax}
\makeatother

\begin{document}
\section{zzz}

aa
$$$$1=0$$$$

\subsection{bbb}

zz
$$$$1=0$$$$
\subsection{bbb}

\section{hhh}

\subsection{lll}

zz
\begin{figure}
\fbox{XXXXX}

\caption{zzz}
\end{figure}

\begin{enumerate}
\item zzz
\item 333
\item kkk
\end{enumerate}
\end{document}


or with memoir and \chapter

\documentclass{memoir}

\makeatletter
\def\@arabic#1{\number\numexpr#1-1\relax}
\makeatother

\begin{document}
\chapter{gg}
\section{zzz}

aa
$$$$1=0$$$$

\subsection{bbb}

zz
$$$$1=0$$$$
\subsection{bbb}

\section{hhh}

\subsection{lll}

zz
\begin{figure}
\fbox{XXXXX}

\caption{zzz}
\end{figure}

\begin{enumerate}
\item zzz
\item 333
\item kkk
\end{enumerate}
\end{document}

• You beat me to it :)
– yo'
Commented Nov 1, 2014 at 14:54
• Good choice to redefine only the arabic numerals -- I'd hate to think how one might go about adjusting Roman numerals and alphabetically labeled sequences...
– Mico
Commented Nov 1, 2014 at 15:01
• @Mico exactly the same change (although romannumeral for 0 is empty so it may look a bit odd) Commented Nov 1, 2014 at 15:05
• @DavidCarlisle - So, redefining \@alph will give an empty number for the letter immediately before "a"? :-)
– Mico
Commented Nov 1, 2014 at 15:16
• @Mico yes if you just subtract 1 as above and rely on the \ifcase that \@alph uses. Alternativeively you could subtract one as above than the redefine \@alph to put something before the first \or (whatever symbol you want for zero) Commented Nov 1, 2014 at 15:20