2

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:

enter image description here

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.

1 Answer 1

3

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
\addtodef{\appendix}{\cftinserthook{toc}{APP}}{}
% 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}

output of code

1
  • 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.
    – JamesT
    Aug 14 at 17:14

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.