3

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.

  • 3
    Use \setcounter{chapter}{-1} – Sigur Nov 1 '14 at 13:50
  • 1
    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. – egreg Nov 1 '14 at 14:54
  • @egreg it's over use of C it addles the mind:-) – David Carlisle Nov 1 '14 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. – jolson Nov 1 '14 at 22:57
  • 1
    @jolson And my example shows he's, with due respect, wrong. – egreg Nov 1 '14 at 23:06
7

enter image description here

\documentclass{article}

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

\begin{document}
\section{zzz}

aa
\begin{equation}1=0\end{equation}

\subsection{bbb}

zz
\begin{equation}1=0\end{equation}
\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
\begin{equation}1=0\end{equation}

\subsection{bbb}

zz
\begin{equation}1=0\end{equation}
\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' Nov 1 '14 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 Nov 1 '14 at 15:01
  • 1
    @Mico exactly the same change (although romannumeral for 0 is empty so it may look a bit odd) – David Carlisle Nov 1 '14 at 15:05
  • @DavidCarlisle - So, redefining \@alph will give an empty number for the letter immediately before "a"? :-) – Mico Nov 1 '14 at 15:16
  • 1
    @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) – David Carlisle Nov 1 '14 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.