回忆录删除章节编号但保留附录编号

回忆录删除章节编号但保留附录编号

我正在创建一本实验室手册,其中\part是年份,\chapter是月份,\section是具体日期。

这是我的文档当前的样子:

在此处输入图片描述

我设法去掉了chapter数字,\mainmatter但这也去掉了章节号(AB等等)。通过阅读memoir.dtxCTAN 上的文件,我发现memoir使用\ifanappendix来测试数字线是否是附录(?),并尝试对其进行修改,如下所示:

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

这似乎不起作用(在图像上,Appendix 1应该.. 2分别在前面有 A 和 B)。我也不确定为什么 Foo、Baz 和 Bar 子部分的数字之间的间距这么大。如果有人能帮我去掉那个空格并只显示章节编号,\appendix我将不胜感激。

梅威瑟:

% 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}

如果这个问题需要分成多个问题,那么请发表评论,我认为它们有点相似,所以将它们分组,但如果它们有很大不同,我很乐意得到纠正。

答案1

\chapternumberlinein的定义memoir比仅仅写出的值要复杂得多,\thechapter这就是重新定义不起作用的原因。我建议改用 memoir 的方法将代码添加到目录中,这对于需要在目录中的不同部分进行更改的情况特别有用。然后我们可以保存原始\chapternumberline定义,并在添加附录后将其插入。

子小节数字的间距由长度控制\cftsubsubsectionnumwidth,因此可以将其重新定义为我使用的较小的值2em,这似乎是合理的,但您可以将其更改为您喜欢的任何值。

\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}

代码输出

相关内容