2

I'm at a loss here.

I've made a macro for setting a 'part' title and number, so that 0 is excluded in the part numbering. I use these to display the part title and number in the heading and in the toc.

For some reason, however, the part title is displayed with the correct numbering in the toc (A., A1. and A2.). But in the actual 'part' the header displays the first parttitle correctly(A. PART NUMBER ZERO), but in the following parts the are displayed incorrectly (A2. PART NUMBER ONE, A3. PART NUMBER TWO). They should be A1. PART NUMBER ONE and A2. PART NUMBER TWO.

I can't seem to find where it count an extra part. I.e. where is part 1(A1.)?

I've tried to string together a mws that shows my problem:

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

Thanks in advance!

  • Unfortunately that doesn't fix it. Thanks though. – Morten Jun 7 '17 at 19:47
3

You need to expand the number when you define \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}
  • @Skillmon right, an \noexpand is missing. – Ulrike Fischer Jun 7 '17 at 19:52
  • Thank you. Maybe I'm doing something wrong, because I don't quite understand your solution. But now 'A. PART NUMBER ZERO' is just repeated in all headers throughout the document? As well as the 'A.#' pagenumber. – Morten Jun 7 '17 at 20:05
  • Not for me. I get "A2. PART NUMBER TWO" above chapter 4. – Ulrike Fischer Jun 7 '17 at 20:24
  • Yeah, so i didn't remove the ´\renewcommand{}´, doh! It works now, thank you so much, both you and @Skillmon! – Morten Jun 8 '17 at 5:28
2

The setting of the header is as far as I know asynchronous. However, expanding the \theDocPart in \pageNumber and \parttitle does work:

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

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.