# Two digit sectioning in memoir class

I would like to have the first 1-9 numbered heading from chapter to subsubsections be two digits.

So instead of:
1 Chapter One
1.1 Section One
1.1.1 Subsection One
1.1.1.1 Subsubsection One

I would like:
01 Chapter One
01.01 Section One
01.01.01 Subsection One
01.01.01.01 Subsubsection One

After the first 9 they should just continue 10, 11, 12 etc. without a zero in front.

• The question is not really memoir related, here is a general solution: tex.stackexchange.com/a/30932/3929, you'll need to use it in a redefinition of \thechapter, \thesection etc. May 14, 2021 at 7:50

## 1 Answer

The code of memoir contains

\renewcommand*{\thechapter}{\@arabic\c@chapter}
\renewcommand*{\thesection}{\thechapter.\@arabic\c@section}
\renewcommand*{\thesubsection}{%
\thesection.\@arabic\c@subsection}
\renewcommand*{\thesubsubsection}{%
\thesubsection.\@arabic\c@subsubsection}


so you have to replace every \@arabic... by \two@digits...

\documentclass{memoir}

\setcounter{secnumdepth}{3}

\makeatletter
\renewcommand*{\thechapter}{\two@digits\c@chapter}
\renewcommand*{\thesection}{\thechapter.\two@digits\c@section}
\renewcommand*{\thesubsection}{%
\thesection.\two@digits\c@subsection}
\renewcommand*{\thesubsubsection}{%
\thesubsection.\two@digits\c@subsubsection}
\makeatother

\begin{document}

\chapter{Foo}
\section{Bar}
\subsection{Baz}
\subsubsection{Bla}

\end{document}


• Ahh, didn't even know that was in the kernel May 14, 2021 at 8:13
• @daleif I found that out quite by accident only last week while looking for the definition of \@firstoftwo (I couldn't remember if it was \long or not). I've been using my own macro for years :-) May 14, 2021 at 8:17
• Legend. This is my favorite kind of answer; one that requires a level of understanding I can forgive myself for not having, and yet being easy to apply in practice. May 15, 2021 at 20:22