3

So in the default book class, the page number for chapters appears at the bottom of the page. I just want the page numbering to alternate left and right, as it does for all other pages.

How can I change the different behavior for pages where there is a chapter?

I have googled the problem and I am aware the package fancyhdr may be of some use, but I don't understand how to use it (yes I read some of the documentation and I still don't understand). So far I just use its default behavior:

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhead[LE,RO]{\slshape \rightmark}
\fancyhead[LO,RE]{\slshape \leftmark}
\fancyfoot[C]{\thepage}

\begin{document}
\Stuff
\end{document}

EDIT: I want the page numbers to appear in the header. I've changed the code to look like this:

\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhead[LE]{\slshape \rightmark}
\fancyhead[RO]{\slshape \leftmark}
\fancyhead[LO,RE]{\thepage}

\begin{document}
\Stuff
\end{document}

What this does is to alternate the pages depending on whether it is odd or even, but for chapters, the pages are still centered. Also, I now have page numbers listed in BOTH the header AND the footer for ALL pages...

3
  • I see you are a new user. Welcome! Now, if your book is fiction (rather than academic, or math), consider using the novel document class, instead of book. Many of the problems you are likely to face, are internally solved within this class. For example, fancyhdr is pre-configured with several menu choices, optimized for fiction (including the one you want). The novel package is not shipped with TeX; you have to get it via your TeX package manager.
    – user139954
    Nov 28, 2017 at 18:50
  • See \fancypagestyle{plain} on pages 7 & 8 of the fancyhdr manual. Nov 28, 2017 at 21:57
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Dec 29, 2017 at 17:30

2 Answers 2

5

The letters in square brackets tell you, which position in the header or footer the contents of the curly brackets will be positioned in. L, R, C are left, right, and center, O and E are odd and even. So \fancyfoot[C]{\thepage} will print the current page number cnetered in the footer. It might be useful to have a look at the documentation.

After your edit, I’d recommend you clear all headers and footers in the pagestyle fancy with \fancyhf{} and redefine the pagestyle plain that is used by the \chapter-command with \fancypagestyle:

\documentclass{book}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}%clear all headers and footers
\fancyhead[LE]{\slshape \rightmark}
\fancyhead[RO]{\slshape \leftmark}
\fancyhead[LO,RE]{\thepage}

\fancypagestyle{plain}{%
\fancyhf{}%clear all headers and footers
\renewcommand{\headrulewidth}{0pt}%header rule invisible
}

\usepackage{lipsum}

\begin{document}
\chapter{Stuff}
\lipsum
\section{More stuff}
\lipsum
\chapter{Different stuff}
\lipsum
\section{Different stuff in a section}
\lipsum
\end{document}
3
  • Hi, this didn't work. I also wanted the pages to appear in the header. I will add some further comments in my original post, give me a few minutes
    – slew123
    Nov 28, 2017 at 18:23
  • Without option twoside this code doesn't work! \documentclass[twoside]{book}
    – user91669
    Nov 28, 2017 at 19:25
  • 1
    The book class uses the option twoside by default. There is no need to specify it explicitly.
    – kmbkrkn
    Nov 28, 2017 at 22:10
2

I found what I was looking for. Put this in the preamble:

\usepackage{etoolbox} 
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[RO]{\slshape \rightmark}
\fancyhead[LE]{\slshape \leftmark}
\fancyhead[LO,RE]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\cfoot{} % get rid of the page number 
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

As far as I understand it, the code below changes the pagestyle of Chapter from plain to fancy.

\usepackage{etoolbox} 
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}

You can clear the page numbers from the footer using:

\cfoot{}

You can adjust the width of the lines by changing the number (or remove them by putting 0pt):

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

Thanks for the help.

You must log in to answer this question.

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