5

I've been working a while now to get the layout the way I want it, but I still have two things that I can't seem to get fixed. I would like to have the page number of the empty page before the start of a chapter on the left side instead of the right side. Furthermore, I would like to have the content page to start on an odd page and again have the page number on the empty page before the content page on the left side. So far, I have:

\documentclass[10pt,twoside]{book}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{etoolbox}
\usepackage{amssymb}
\usepackage{bbold}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{fancyhdr}
\usepackage[PetersLenny]{fncychap}
\usepackage{courier}
\usepackage[a4paper,inner=4cm,outer=1.5cm]{geometry}
\usepackage[nottoc]{tocbibind}
\usepackage[font=small,format=plain,labelfont=bf,up,]{caption}
\usepackage{flafter}

\let\origdoublepage\cleardoublepage
\newcommand{\clearemptydoublepage}{%
  \clearpage
  {\pagestyle{plain}\origdoublepage}%
}

\newcommand{\tstamp}{\today}   
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\lhead[\fancyplain{}{\thepage}]         {\fancyplain{}{\rightmark}}
\chead[\fancyplain{}{}]                 {\fancyplain{}{}}
\rhead[\fancyplain{}{\rightmark}]       {\fancyplain{}{\thepage}}
\lfoot[\fancyplain{}{}]                 {\fancyplain{\tstamp}{\tstamp}}
\cfoot[\fancyplain{\thepage}{}]         {\fancyplain{\thepage}{}}
\rfoot[\fancyplain{\tstamp} {\tstamp}]  {\fancyplain{}{}}

\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyhead[RO,RE]{\thepage} %RO=right odd, RE=right even
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}


\let\cleardoublepage\clearemptydoublepage

\begin{document}

blabla

\end{document}

To be honest, I don't know what any of the code means (mainly used Google, this forum and trial/error to get it like that). But I was wondering if anybody knows the answers to the two problems I have?

This is an edit to clarify what my specifications are:

Ok, I would like to have on all even pages, the page number on the left top side and on all the odd pages the page number on the right side. Furthermore, I would like to have the chapter name on the right side of all the even \textit{after} the start of the first chapter (i.e. after the \mainmatter command and the section title on the left side of odd pages. So to clarify, all the pages with roman number should only have the page number, but once the first chapter after the table of content has started I would like to have the chapter name on the even pages and section name on the odd pages.

2 Answers 2

6

Probably just changing the line:

\fancyhead[RO,RE]{\thepage} %RO=right odd, RE=right even

to

\fancyhead[RO,LE]{\thepage} %RO=right odd, LE=left even

is all what you need?

3
  • That is great, it seems to have fixed both problems. Thank you so much (I can't seem to vote on you're answer because I don't have enough reputation).
    – Hunter
    Jul 8, 2013 at 15:08
  • @Hunter Now you can vote ;)
    – user11232
    Jul 9, 2013 at 0:34
  • Yeah, I've voted already ;)
    – Hunter
    Jul 9, 2013 at 5:11
3

Here's a setup for getting what you want; fine tune it, I possibly didn't catch all of your specifications that are hidden in those old fashioned fancyhdr commands; the "modern" syntax with \fancyheader and \fancyfoot, together with \fancypagestyle is more flexible.

The key was to define a particular page style numberleft for the blank pages, which is activated with a straightforward definition of \cleardoublepage.

\documentclass[10pt,twoside]{book}
\usepackage{fancyhdr}
\usepackage[nottoc]{tocbibind}
\usepackage{lipsum}

\makeatletter
\renewcommand\cleardoublepage{%
  \clearpage
  \if@twoside
    \ifodd\c@page
      % do nothing
    \else
      \hbox{}\thispagestyle{numberleft}\newpage % changed line
      \if@twocolumn
        \hbox{}\newpage
      \fi
    \fi
  \fi}
\makeatother

\newcommand{\tstamp}{\today}   

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhf{}
\fancyhead[LO]{\rightmark}
\fancyhead[RO,LE]{\thepage}
\fancyhead[RE]{\leftmark}
\fancyfoot[L]{\tstamp}

\fancypagestyle{plain}{%
  \fancyhf{} % clear all header and footer fields
  \fancyhead[LO,RE]{\thepage} %RO=right odd, RE=right even
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}}
\fancypagestyle{numberleft}{%
  \fancyhf{} % clear all header and footer fields
  \fancyhead[L]{\thepage} %RO=right odd, RE=right even
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}}

\begin{document}

\frontmatter

\tableofcontents

\mainmatter

\chapter{A chapter}

\section{A section}

\lipsum[1-20]

\chapter{B chapter}

\section{B section}

\lipsum[1-20]

\end{document}

enter image description here


After reading the complete specifications, here's a new version; the only change I propose to your specs is not to print the page number if the last page of the front matter is empty; you can revert it by removing \if@mainmatter and \fi from the definition of the numberleft page style.

\documentclass[10pt,twoside]{book}
\usepackage{fancyhdr}
\usepackage[nottoc]{tocbibind}
\usepackage{lipsum}

\makeatletter
\renewcommand\cleardoublepage{%
  \clearpage
  \if@twoside
    \ifodd\c@page
      % do nothing
    \else
      \hbox{}\thispagestyle{numberleft}\newpage % changed line
      \if@twocolumn
        \hbox{}\newpage
      \fi
    \fi
  \fi}
\makeatother

\newcommand{\tstamp}{\today}   

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhf{}
\makeatletter
\fancyhead[RO]{\if@mainmatter\rightmark\fi}
\fancyhead[L]{\thepage}
\fancyhead[RE]{\if@mainmatter\leftmark\fi}
\fancyfoot[L]{\tstamp}

\fancypagestyle{plain}{% for chapter start pages
  \fancyhf{} % clear all header and footer fields
  \fancyhead[L]{\thepage} %RO=right odd, RE=right even
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}}
\fancypagestyle{numberleft}{% for otherwise blank pages
  \fancyhf{} % clear all header and footer fields
  \fancyhead[L]{\if@mainmatter\thepage\fi} %RO=right odd, RE=right even
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}}
\makeatletter

\begin{document}

\frontmatter

\tableofcontents

\mainmatter

\chapter{A chapter}

\section{A section}

\lipsum[1-20]

\chapter{B chapter}

\section{B section}

\lipsum[1-20]

\end{document}
6
  • Hi egreg, thanks for your reply. I've tried to finetune it the way I had it before, but I can't seem to make it work - the fancyhdr package is just too confusing for me :(. Is there anyway it is possible to make it work with my old code? It is just that the code has some very specific things that I like about it, which took me literally days to get it working like that, and I can't afford to spend that time again on a whole new code.
    – Hunter
    Jul 8, 2013 at 14:06
  • @Hunter Can you spell out the specifications for your headers?
    – egreg
    Jul 8, 2013 at 14:38
  • Ok, I would like to have on all even pages, the page number on the left top side and on all the odd pages the page number on the right side. Furthermore, I would like to have the chapter name on the right side of all the even \textit{after} the start of the first chapter (i.e. after the \mainmatter command and the section title on the odd pages. So to clarify, all the pages with roman number should only have the page number, but once the first chapter after the table of content has started I would like to have the chapter name on the even pages and section name on the odd pages.
    – Hunter
    Jul 8, 2013 at 14:55
  • @Hunter Please, add the specifications to your questions, where they will be more easily understood.
    – egreg
    Jul 8, 2013 at 14:57
  • @Hunter I added a new version
    – egreg
    Jul 8, 2013 at 15:07

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.