计步器行为异常

计步器行为异常

我很茫然。

我制作了一个宏来设置“部件”标题和编号,这样部件编号中就不会包含 0。我使用这些宏在标题和目录中显示部件标题和编号。

但是,出于某种原因,部分标题在目录中以正确的编号显示(A.、A1. 和 A2.)。但在实际的“部分”中,标题正确显示了第一个部分标题(A. 部分编号零),但在以下部分中显示不正确(A2. 部分编号一、A3. 部分编号二)。它们应该是 A1. 部分编号一和 A2. 部分编号二。

我似乎找不到哪里算作额外部分。例如,第 1 部分(A1.)在哪里?

我试图串起一个显示我的问题的 mws:

\documentclass[11pt, oneside, a4paper]{memoir}

\usepackage{lipsum}

\newcounter{DocPart}
\setcounter{DocPart}{0}
\newcommand{\pageNumber}{}
\newcommand{\parttitle}{}
\renewcommand{\part}[1]{
    \ifnum\theDocPart = 0
         \renewcommand{\parttitle}{A. #1}
         \renewcommand{\pageNumber}{A.\thepage}
         \cftaddtitleline{toc}{part}{A. #1}{}
    \else
        \renewcommand{\parttitle}{A\theDocPart. #1}
        \renewcommand{\pageNumber}{A\theDocPart.\thepage}
        \cftaddtitleline{toc}{part}{A\theDocPart. #1}{}
    \fi
    \stepcounter{DocPart}
}

\makepagestyle{test}
\makeoddhead{test}{\pageNumber}{}{\parttitle}
\pagestyle{test}

\begin{document}

\part{PART NUMBER ZERO} % I want this to say A. PART NUMBER ZERO in the header, which it does
\chapter{FAKE CHAPTER ONE}
\thispagestyle{test}
\lipsum[88]
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum[120]
\newpage


\tableofcontents*


\part{PART NUMBER ONE} % I want this to say A1. PART NUMBER ONE in the header
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum

\part{PART NUMBER TWO} % I want this to say A2. PART NUMBER TWO in the header
\chapter{FAKE CHAPTER THREE}
\thispagestyle{test}
\lipsum


\end{document}

提前致谢!

答案1

定义 \parttitle 时需要扩展数字:

\documentclass[11pt, oneside, a4paper]{memoir}

\usepackage{lipsum}

\newcounter{DocPart}
\setcounter{DocPart}{0}
\newcommand{\pageNumber}{}
\newcommand{\parttitle}{}
\renewcommand{\part}[1]{%
    \ifnum\theDocPart = 0
         \renewcommand{\parttitle}{A. #1}
         \renewcommand{\pageNumber}{A.\thepage}
         \cftaddtitleline{toc}{part}{A. #1}{}
    \else
        \edef\parttitle{A\theDocPart. #1}%<----
        \edef\pageNumber{A\theDocPart.\noexpand\thepage}%<-----
        \cftaddtitleline{toc}{part}{A\theDocPart. #1}{}
    \fi
    \stepcounter{DocPart}
}

\makepagestyle{test}
\makeoddhead{test}{\pageNumber}{}{\parttitle}
\pagestyle{test}

\begin{document}

\part{PART NUMBER ZERO} % I want this to say A. PART NUMBER ZERO in the header, which it does
\chapter{FAKE CHAPTER ONE}
\theDocPart \thispagestyle{test}
\lipsum[88]
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum[120]

\newpage

\tableofcontents*


\part{PART NUMBER ONE} % I want this to say A1. PART NUMBER ONE in the header
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum


\part{PART NUMBER TWO} % I want this to say A2. PART NUMBER TWO in the header
\chapter{FAKE CHAPTER THREE}
\thispagestyle{test}
\lipsum


\end{document}

答案2

据我所知,标头的设置是异步的。但是,扩展\theDocPartin\pageNumber\parttitle确实有效:

\documentclass[11pt, oneside, a4paper]{memoir}

\usepackage{lipsum}

\newcounter{DocPart}
\setcounter{DocPart}{0}
\newcommand{\pageNumber}{}
\newcommand{\parttitle}{}
\renewcommand{\part}[1]{
    \ifnum\theDocPart = 0
         \renewcommand{\parttitle}{A. #1}
         \renewcommand{\pageNumber}{A.\thepage}
         \cftaddtitleline{toc}{part}{A. #1}{}
    \else
        \xdef\parttitle{A\theDocPart. #1}
        \xdef\pageNumber{A\theDocPart.\noexpand\thepage}
        \cftaddtitleline{toc}{part}{A\theDocPart. #1}{}
    \fi
    \stepcounter{DocPart}
}

\makepagestyle{test}
\makeoddhead{test}{\pageNumber}{}{\parttitle}
\pagestyle{test}

\begin{document}

\part{PART NUMBER ZERO} % I want this to say A. PART NUMBER ZERO in the header, which it does
\chapter{FAKE CHAPTER ONE}
\thispagestyle{test}
\lipsum[88]
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum[120]
\newpage


\tableofcontents*


\part{PART NUMBER ONE} % I want this to say A1. PART NUMBER ONE in the header
\chapter{FAKE CHAPTER TWO}
\thispagestyle{test}
\lipsum

\part{PART NUMBER TWO} % I want this to say A2. PART NUMBER TWO in the header
\chapter{FAKE CHAPTER THREE}
\thispagestyle{test}
\lipsum


\end{document}

相关内容