3

I am writing a book with several parts and chapters that has a general introduction. I defined a header style for most of the book, that I can easily locally disable for a few pages with \pagestyle{empty}. The header has my name in even pages and the chapter mark (Chapter XX) in odd pages.

Now I would like to have a different kind of header for the introduction to avoid having an ugly "Chapter 0" as a header. I want the header to have my name in even pages and "introduction" in odd pages.

I defined a new style using fancyhdr. However nothing seems to work. After a few pages, I get the "Chapter 0" back in the introduction, and it lasts until the next chapter, although I have cleared the page. Can you please tell me wat is wrong in my MWE?

  \documentclass[12pt, A4]{book}

  \usepackage{tocbibind}
  \usepackage{blindtext}  
  \usepackage{emptypage}
  %%%%% Header
  \usepackage{fancyhdr}


  \fancypagestyle{style1}{
  \fancyhead[CO]{Introduction}
  \fancyfoot[CE]{Me}
  \fancyfoot[CE,CO]{\thepage}
  \renewcommand{\headrulewidth}{0pt}
  }

  \pagestyle{fancy}
  \fancyhf{}
  \fancyhead[CE]{Me}
  \fancyhead[CO]{\chaptername \  \thechapter}
  \fancyfoot[CE,CO]{\thepage}
  \renewcommand{\headrulewidth}{0pt}





  \begin{document}


  {\pagestyle{empty} 
  \tableofcontents
  \clearpage}


  \clearpage
  {\pagestyle{style1}
  \chapter*{Introduction}

  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext

    }
  \clearpage

  \pagestyle{fancy}

  \part{Thing}
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \chapter{Thing thing}
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \chapter{thingthingthing}

  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext


  \end{document}
1
  • (not related) there is no A4 option for book class it's a4paper.
    – touhami
    Jun 23, 2016 at 21:34

2 Answers 2

5

Use \leftmark in the header. There is also a \rightmark. However, here in book-class, with default options, \leftmark would hold the chapter-name, with some formatting. This can be changed of course.

A few places throughout your document, you need to change what is in the header, as you haven't yet defined a non-starred \chapter. Then we can update \rightmark with \markkright, but there is no \markleft-command available. A shame really, could be useful. \markboth{left}{right} could be used here, though.

Suggestions

  • Instead of issuing new \pagestyle for when you want a single page to be different. Use \thispagestyle, which only changes the style for that one page. Have the first/main \pagestyle in the preamble, keeps it a bit tidier. Content and settings should in my opinion be separated as much as possible.
  • You don't need so many \clearpages. In book-class, the default option is openright, which means that every chapter will start at only right-hand sides.

Code

  \documentclass[12pt, a4paper]{book}

  \usepackage{tocbibind}
  \usepackage{lipsum}  
  \usepackage{emptypage}
  %%%%% Header
  \usepackage{fancyhdr}

  \pagestyle{fancy}
  \fancyhf{}
  \fancyhead[CE]{Me}
  \fancyhead[CO]{\leftmark}
  \fancyfoot[CE,CO]{\thepage}
  \renewcommand{\headrulewidth}{0pt}
    \pagestyle{fancy}
  \begin{document}

  \thispagestyle{empty}
  {\renewcommand\addcontentsline[3]{}
  \tableofcontents}
  \clearpage

  \chapter*{Introduction}\markboth{Introduction}{}
    \lipsum[1-9]
  \clearpage

  \part{Thing} \markboth{Part thing}{}

  \lipsum[1-10]

  \chapter{Thing thing}

  \lipsum[1-7]
  \chapter{thingthingthing}

  \lipsum[1-8]
  \end{document}
2
  • Thank you, this works brilliantly, except that I get a header for the TOC
    – Doon_Bogan
    Jun 24, 2016 at 14:23
  • Oh, I see what you mean now. Use {\renewcommand\addcontentsline[3]{} \tableofcontents} The reason it got added was that you specified it with the package tocbibind
    – Runar
    Jun 25, 2016 at 4:17
1

Here is a solution. as suggested in above answer use of \leftmark is recommended.

You can do what you want in once using \fancyhead[CO]{\ifnum\value{chapter}>0 \chaptername \ \thechapter\else\leftmark\fi}

if you want you can do \fancyhead[CO]{\ifnum\value{chapter}>0 \chaptername \ \thechapter\ \fi\leftmark}

\documentclass[12pt, a4paper]{book}

  \usepackage{tocbibind}
  \usepackage{blindtext}  
  \usepackage{emptypage}
  %%%%% Header
  \usepackage{fancyhdr}
  \pagestyle{fancy}
  \fancyhf{}
  \fancyhead[CE]{Me}
  \fancyhead[CO]{\ifnum\value{chapter}>0 \chaptername \  \thechapter\else\leftmark\fi}
  \fancyfoot[CE,CO]{\thepage}
  \renewcommand{\headrulewidth}{0pt}

  \begin{document}

  \pagestyle{empty} 

  \tableofcontents
  \chapter*{Introduction}
  \pagestyle{fancy}
  \markboth{Introduction}{Introduction}
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext

  \part{Thing}
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \chapter{Thing thing}
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \chapter{thingthingthing}

  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext
  \Blindtext

  \end{document}
2
  • There is no A4 option for book, it is a4paper.
    – egreg
    Jun 23, 2016 at 22:07
  • I did not know this ;-)
    – touhami
    Jun 23, 2016 at 22:12

You must log in to answer this question.

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