6

Minimal example (the problem is obvious):

\documentclass[]{report}

\makeatletter
\def\@makechapterhead#1{
    \vspace*{-5.0em}
    {\parindent \z@  \normalfont
    \interlinepenalty\@M
    \LARGE{0\thechapter}
    \par\vspace{0.25cm}
    \flushleft\MakeUppercase{#1}}
    \par\vspace{3.5em}
}
\makeatother

\begin{document}

\chapter{First Chapter}
\setcounter{chapter}{9}
\chapter{Tenth Chapter}

\appendix
\chapter{Appendix A}

\end{document}

Edit: I forgot to mention something important. Only the displayed chapter numbers should have 0s in front of them, not definitions, theorems, etc. That is: Chapter 01, Definition 1.1., etc.

3 Answers3

8

Easy with \numprintand its \nplpadding command:

\documentclass[]{report}

\usepackage{numprint, apptools}

\makeatletter
\def\@makechapterhead#1{
    \vspace*{-5.0em}
    {\parindent \z@ \normalfont
    \interlinepenalty\@M
    \LARGE{\ifappendix\Alph{chapter}\else\nplpadding{2}\numprint{\arabic{chapter}}\fi}%
    \par\vspace{0.25cm}
    \flushleft\MakeUppercase{#1}}
    \par\vspace{3.5em}
    \renewcommand\thechapter{\ifappendix\Alph{chapter}\else\npnolpadding\arabic{chapter}\fi}}
\makeatother

\usepackage{amsthm}
\newtheorem{thm}{Theorem}[chapter]

\begin{document}

\chapter{First Chapter}

\begin{thm}
  A first theorem
\end{thm}
\setcounter{chapter}{9}
\chapter{Tenth Chapter}

\appendix
\chapter{Appendix A}
\begin{thm}
  Another theorem
\end{thm}

\end{document} 

enter image description here

enter image description here

Bernard
  • 271,350
  • Actually there's something I forgot to mention (sorry). I only want the displayed chapter numbers to have 0s. The definitions, theorems, etc. will be labeled normally. Any way to fix that? I'll leave the answer accepted because it's not that big of a deal, but I would like to fix it if possible. – Randy Randerson Jun 06 '15 at 13:53
  • @RandyRanderson: please see my updated answer. – Bernard Jun 06 '15 at 14:07
  • @Mico: with \newtheorem{thm}{Theorem}[chapter], it is modified, so I had to change my code. – Bernard Jun 06 '15 at 14:09
  • Shouldn't the chapter numbering style be reset explicitly to \Alph in the appendix? Without such a reset, one would seem to get "01" in the page header instead of "A". – Mico Jun 06 '15 at 14:18
  • It doesn't have to. It seems the \appendix switch does it.removed. It's fixed now. – Bernard Jun 06 '15 at 14:23
  • Hmm, I get a "01" in the header row above "Appendix A" when I run your latest code. – Mico Jun 06 '15 at 14:26
  • @Mico: solved, with \ifappendix from apptools. – Bernard Jun 06 '15 at 14:55
  • But now the theorem-numbering gremlin is back. (Sorry, I really don't mean to torture you!) – Mico Jun 06 '15 at 15:01
  • Anyway, I like that sort of challenges. However the theorem numbering is normal in my case. How did you do? – Bernard Jun 06 '15 at 15:04
  • @Mico: Solved again – until next time… – Bernard Jun 06 '15 at 15:16
3

You can adjust the printing of \thechapter within \@makechapterhead to insert a 0 only if the value of the chapter counter is less than 10:

enter image description here

\documentclass{report}

\usepackage{etoolbox}

\makeatletter
\patchcmd{\@makechapterhead}% <cmd>
  {\thechapter}% <search>
  {\expandafter\ifx\@chapapp\appendixname\else\ifnum\value{chapter}<10 0\fi\fi\thechapter}% <replace>
  {}{}% <success><failure>
\makeatother

\usepackage{amsthm}
\newtheorem{thm}{Theorem}[chapter]

\begin{document}

\chapter{First Chapter}

\begin{thm}
  A first theorem
\end{thm}
\setcounter{chapter}{9}
\chapter{Tenth Chapter}

\appendix
\chapter{Appendix A}
\begin{thm}
  Another theorem
\end{thm}

\end{document}

The nested condition in the "replacement clause" of \patchcmd first checks whether you're in the appendix or not. If you aren't, then it prepends the \thechapter counter with 0, similar to the kernel \two@digits macro.

Werner
  • 603,163
  • +1; Your patch is basically the command \two@digits defined in the LaTeX kernel, so you could just write \two@digits{\thechapter}. – Pier Paolo Jun 07 '15 at 14:51
  • @Mico: Thanks for picking that up. I've corrected for this in the updated post. – Werner Jun 09 '15 at 06:01
2

Here is a solution for ConTeXt users to force double digit numbers for the chapters. With the use of the \startsectionblockenvironment command one could provide setups which are only applied for a certain sectionblock environment.

\startsectionblockenvironment[bodypart]
    \setuphead[chapter][deepnumbercommand=\twodigits]
\stopsectionblockenvironment

\starttext

\startsectionblock[bodypart]

\chapter{First chapter}

\stopsectionblock

\startsectionblock[appendix]

\chapter{Appendix A}

\stopsectionblock

\stoptext

To have the same layout for the heading with the number on a separate line one has to write its own rendering alternative for it.

\defineheadalternative
  [stacked]
  [alternative=vertical,
   renderingsetup=headalternative:stacked]

\startsetups[headalternative:stacked]
    \vbox {
        \headsetupspacing
        \begstrut
        \ifconditional\headshownumber
            \headnumbercontent
            \par
        \fi
        \headtextcontent
    }
\stopsetups

After this is done with can load this new rendering with the alternative key from \setuphead.

\setuphead
  [chapter]
  [alternative=stacked,
   textstyle=WORD]
Wolfgang Schuster
  • 9,400
  • 1
  • 16
  • 19