# Memoir removing chapter numbering but keeping appendix numbering

I am creating a labbook for which the \part is the year, the \chapter is the month and the \section is the specific day.

This is how my document currently looks:

I managed to get rid of the chapter numbers in \mainmatter but this also got rid of the chapter numbers (A, B etc.). From reading the memoir.dtx file on CTAN, I found that memoir uses \ifanappendix to test for whether the number line is an appendix or not (?) and attempted to modify it like:

\renewcommand{\chapternumberline}[1]{\ifanappendix \thechapter. \else \fi}


Which doesn't seem to work (on the image, Appendix 1 and .. 2 should have A and B in front respectively). I am not sure why the spacing between the numbers for Foo, Baz and Bar subsections are so large either. If anyone could help me get rid of that space and have chapter numbers for \appendix only I would be appreciative.

MWE:

% arara: pdflatex: {options: [-halt-on-error]}
% arara: pdflatex: {options: [-halt-on-error]}

\documentclass[11pt,oneside]{memoir}

% From memoir manual p. 156 the \renewcommand was found
%\renewcommand{\chapternumberline}[1]{} % To create blank chapter numbers
\renewcommand{\chapternumberline}[1]{\ifanappendix \thechapter. \else \fi}

% Copied exactly from memoir manual p. 163
\let\oldcftsf\cftsectionfont% save definition of \cftsectionfont
\let\oldcftspn\cftsectionafterpnum% and of \cftsectionafterpnum
\renewcommand*{\cftsectionfont}{%
\let\oldnl\numberline% save definition of \numberline
\renewcommand*{\numberline}[1]{}% change it
\oldcftsf} % use original \cftsectionfont
\renewcommand*{\cftsectionafterpnum}{%
\let\numberline\oldnl% % restore orginal \numberline
\oldcftspn} % use original \cftsectionafterpnum

% From https://tex.stackexchange.com/a/215164/273733
\makeatletter
\def\cl@section{}
\makeatletter
\renewcommand{\thesubsection}{\arabic{subsection}}

\setsecnumdepth{subparagraph}
\settocdepth{subparagraph}

\begin{document}

\tableofcontents*

\part{2022}
\chapter{August}
Foo
\newpage
\section{\today}
Foo
\subsection{Foo}
Bar
\subsubsection{Baz}
Baz

\subsection{Bar}
Foo
\subsubsection{Baz}
Baz

\newpage
\section{15/08/2022}
Foo
\subsection{Foo}
Bar
\subsubsection{Baz}
Baz

\subsection{Bar}
Foo
\subsubsection{Baz}
Baz

\appendix
\chapter{Appendix 1}
Foo
\section{Testing}
bar
\chapter{Appendix 2}
Foo
\section{Testing}
bar

\end{document}


If this question needs splitting into multiple questions then please comment, I think they are somewhat similar so grouped them but I am happy to be corrected if they're very different.

The definition of \chapternumberline in memoir is much more complex than just writing out the value of \thechapter which is why your redefinition doesn't work. I would recommend instead using memoir's methods to add code to the TOC that is especially useful for cases where things need to be changed in different parts of the TOC. Then we can save the original \chapternumberline definition, and insert it after the appendix is added.

The spacing of the subsubsection numbers is controlled by the length \cftsubsubsectionnumwidth so that can be redefined to something smaller I've used 2em which seems reasonable, but you change it to whatever you like.

\documentclass[11pt,oneside]{memoir}

% From memoir manual p. 156 the \renewcommand was found
%\renewcommand{\chapternumberline}[1]{} % To create blank chapter numbers
% save original \chapternumberline definition
\let\oldchapnumline\chapternumberline
\renewcommand{\chapternumberline}[1]{}
% create code to be inserted at the appendix to restore the original
\cftinsertcode{APP}{\let\chapternumberline\oldchapnumline}
% add the insertion code to the \appendix command
% Copied exactly from memoir manual p. 163
\let\oldcftsf\cftsectionfont% save definition of \cftsectionfont
\let\oldcftspn\cftsectionafterpnum% and of \cftsectionafterpnum
\renewcommand*{\cftsectionfont}{%
\let\oldnl\numberline% save definition of \numberline
\renewcommand*{\numberline}[1]{}% change it
\oldcftsf} % use original \cftsectionfont
\renewcommand*{\cftsectionafterpnum}{%
\let\numberline\oldnl% % restore orginal \numberline
\oldcftspn} % use original \cftsectionafterpnum
\setlength{\cftsubsubsectionnumwidth}{2em}
% From https://tex.stackexchange.com/a/215164/273733
\makeatletter
\def\cl@section{}
\makeatletter
\renewcommand{\thesubsection}{\arabic{subsection}}

\setsecnumdepth{subparagraph}
\settocdepth{subparagraph}

\begin{document}

\tableofcontents*

\part{2022}
\chapter{August}
Foo
\newpage
\section{\today}
Foo
\subsection{Foo}
Bar
\subsubsection{Baz}
Baz

\subsection{Bar}
Foo
\subsubsection{Baz}
Baz

\newpage
\section{15/08/2022}
Foo
\subsection{Foo}
Bar
\subsubsection{Baz}
Baz

\subsection{Bar}
Foo
\subsubsection{Baz}
Baz

\appendix
\chapter{Appendix 1}
Foo
\section{Testing}
bar
\chapter{Appendix 2}
Foo
\section{Testing}
bar

\end{document}


• Just want to add for any future people, ensure the code goes before your packages (I have files I \include solely for packages, macros etc.). The code above failed in my main document (! Illegal parameter number in definition of \appendix) but when including it before packages, it worked as intended. Must be a clash between a package and the code so use before loading packages. Aug 14 at 17:14