I'm writing a custom class based on book.cls for our office's publication series, but I've hit a problem in how to set up a conditional.

Some of the publications are part->chapter->section while others are just chapter->section. Our publication format requires that the alternating page footers are short title (odd page) and either part or chapter (even page).

My question is: how can I determine of a document structure has parts, and if so change the footer accordingly?

  • 2
    after a part the \value{part} will be bigger than 0, if you want to know from the start that the document has parts either you will need to invent a new command that declares that, or at end of document write the value of the part counter to the aux file so detect on the next run whether parts are used Commented Dec 9, 2015 at 18:56
  • I would guess that if I test \value{part}>0 in the class definition (i.e. \ifnum \value{part}>0...\fi) for the header/footer to conditionally set/define a partmark instead of chaptermark?
    – JSCard
    Commented Dec 23, 2015 at 15:25
  • @DavidCarlisle, that worked great... nested an \ifnum \value{part} >\m@ne to test for part else set chaptermark. If you drop your comment to an answer, I'll mark it.
    – JSCard
    Commented Dec 29, 2015 at 17:53

1 Answer 1


Here's a modification of https://tex.stackexchange.com/a/241999/4427



\usepackage{lipsum} % just for the example

\fancyfoot[CE]{Short title}

  \markboth{Part \thepart: #1}{}%
    \markboth{Chapter \thechapter: #1}{}%





\part{First Part}

\chapter{Title A}






If you comment out \part, you get chapters in the footer. Works with or without hyperref.

  • Thanks @egreg, but I'm doing this in a custom class file and trying to stay away from using fancyhdr if I can. It would require a lot of re-coding for some other things I'm doing in there.
    – JSCard
    Commented Dec 29, 2015 at 17:51
  • @Scard The information you gave was insufficient, then. Do you just use the standard \pagestyle{headings}? Or do you define a new one? It's impossible to know what you have in the class, isn't it?
    – egreg
    Commented Dec 29, 2015 at 17:54
  • @ egreg yes... I re-wrote the \pagestyle{headings} in the custom class to test the \value{part} and set the marks accordingly. Your solution would work great otherwise. Meant no slight to your answer, just not quite what I was aiming for. I needed to figure out how to test the conditional case for some other things in there as well.
    – JSCard
    Commented Dec 29, 2015 at 17:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .