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.

5
  • 3
    Use \setcounter{chapter}{-1}
    – Sigur
    Commented Nov 1, 2014 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
    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.
    – jolson
    Commented Nov 1, 2014 at 22:57
  • 1
    @jolson And my example shows he's, with due respect, wrong.
    – egreg
    Commented Nov 1, 2014 at 23:06

1 Answer 1

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}
6
  • 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
  • 1
    @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
  • 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) Commented Nov 1, 2014 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .