2

Consider the following MWE:

\documentclass{book}

\usepackage[pagestyles]{titlesec}

\usepackage{lipsum}

\newpagestyle{myps}[\sffamily]{
  \sethead[\thepage][][\chaptertitle~\thechapter]  % even
          {\thesection~\sectiontitle}{}{\thepage} % odd
}

\pagestyle{myps}

\begin{document}

\chapter{Introduction}
\lipsum[1-5]

\chapter*{Acknowledgements}
\chaptermark{Acknowledgements}
\lipsum[1-5]

\end{document}

The marks in the second page of the Acknowledgements chapter still prints as Acknowledgements 1, i.e. they print the chapter number of the previous one.

What I'de need to get is Acknowledgements on the headers, without any chapter number, since the chapter is unnumbered.

How to get the expected behavior?

  • Could it be because the contents of both chapters is the same? ;o) – Bernard Aug 2 '18 at 10:21
  • I don’t think the content of the chapters have anything to do with the headers marks – gigabytes Aug 2 '18 at 10:31
  • Starred sectioning commands do not set marks. You have to set it manually: \chapter*{Acknowledgements}\chaptermark{Acknowledgements}. But the wrong chapter number still remains. – esdd Aug 2 '18 at 10:32
  • Ok, I was missing that, but then how can I detect in the head that the current chapter is unnumbered and avoid printing the number? – gigabytes Aug 2 '18 at 10:50
  • @esdd: The problem is that titleps normally doesn't use marks. – Bernard Aug 2 '18 at 10:50
3

A solution consists in redefining \titleformat{\chapter}... and using the numberless key to have different \chaptermarks for numbered and unnumbered chapters:

\documentclass{book}

\usepackage[pagestyles, explicit]{titlesec}

\titleformat{\chapter}[display]{\chaptermark{#1 \thechapter}\bfseries}{\huge\chaptername \thechapter}{4ex}{\Huge#1}%
\titleformat{name=\chapter, numberless}[block]{\chaptermark{#1}\bfseries}{}{0ex}{\Huge#1}

\usepackage{lipsum}

\newpagestyle{myps}[\sffamily]{%
  \sethead[\thepage][][\chaptertitle]% even
          {\thesection~\sectiontitle}{}{\thepage} % odd
}

\pagestyle{myps}

\begin{document}

\chapter{Introduction}
\lipsum[1-5]
\cleardoublepage
\chapter*{Acknowledgements}
\lipsum[1-2]

\section{A test section}
\lipsum[3-20]

\end{document} 

enter image description here enter image description here

  • +1 But I think, ~\ifthechapter{}{\thechapter} should be removed. In the example it inserts only a space. \ifthechapter seems to be a test, if counter secnumdepth is at least 0. – esdd Aug 2 '18 at 18:00
  • @esdd: You're right. It's the remnants of a first trial (without using \chaptermark) wich didn't produce anything useful. Actually, I don't fully understand how this test works, and looking at the code details in the package didn't help. – Bernard Aug 2 '18 at 18:11

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.