2

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.

1
  • 2
    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. – daleif May 14 at 7:50
5

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{\@arabic...}

\documentclass{memoir}

\setcounter{secnumdepth}{3}

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

\begin{document}

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

\end{document}

enter image description here

3
  • Ahh, didn't even know that was in the kernel – daleif May 14 at 8:13
  • 2
    @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 :-) – campa May 14 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. – Faergen May 15 at 20:22

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.