13

See the MWE below. How can I achieve (in the standard book class) that despite the oneside option odd and even pages are distinguished in the header? I would like to have that, also with oneside printing, the header of odd pages displays the chapter while the header of even pages displays the section, just as it would be the case without the oneside option.

\documentclass[oneside]{book}

\usepackage{lipsum}
\usepackage{fancyhdr}

\usepackage[
  a4paper,                                    
  textwidth=16cm,                             
  outer=2cm,
  textheight=45\baselineskip,
  headheight=\baselineskip,
  includehead=true,% Default
  heightrounded,
]{geometry}

\pagestyle{fancy}
\fancyhead{}
\fancyhead[LO]{\leftmark}
\fancyhead[RE]{\rightmark}
\fancyhead[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}

\begin{document}

\chapter{Chapter One}
\section{Section One of Chapter One}
\lipsum
\lipsum
\section{Section Two of Chapter One}
\lipsum
\lipsum

\end{document}
9
  • 2
    Why use oneside? Just set a symmetrical page geometry with the geometry package. Aug 28, 2012 at 9:37
  • Well, oneside has some (desired) side-effects, for example, \cleardoublepage behaves like \clearpage ... therefore I use the option. Of course, I could redefine \renewcommand{\cleardoublepage}{\clearpage}for the oneside version ... but just now I am not sure whether oneside has further consequences I am overlooking ...
    – lpdbw
    Aug 28, 2012 at 9:40
  • Moreover, even in the oneside version I dont really want a symmetric layout, but the inner margin should be larger so as to allow for binding
    – lpdbw
    Aug 28, 2012 at 9:49
  • Still I think twoside is the way to go. Aug 28, 2012 at 9:51
  • 2
    OK, with \renewcommand{\cleardoublepage}{\clearpage} at the beginning of the preamble there are no more blank pages produced by twoside. But how do you solve the problem with changing inner and outer margins? (I edited my question and added my page layout) Ah, I see, it's the asymmetric option in the geometry package I need.
    – lpdbw
    Aug 28, 2012 at 10:03

2 Answers 2

14

Another alternative is to use oneside, but toggle headers based on the page number, like this:

\documentclass[oneside]{book}

\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{ifthen}

\pagestyle{fancy}
\fancyhead{}
\fancyhead[L]{\ifthenelse{\isodd{\value{page}}}{\leftmark}{\rightmark}}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}

\begin{document}

\chapter{Chapter One}
\section{Section One of Chapter One}
\lipsum
\lipsum
\section{Section Two of Chapter One}
\lipsum
\lipsum

\end{document}
8
  • What are the pros and cons of both solutions? I mean, is one of the two solutions "cleaner"/more elegant/more robust or whatever than the other? I don't have a feeling for this and I am not sure which answer should be the accepted one ...
    – lpdbw
    Aug 29, 2012 at 12:40
  • @lpdbw Although I initially suggested twoside, I think sticking to oneside is cleaner after all. twoside just has too many side effects like symmetrical margins on spreads etc. Aug 29, 2012 at 12:45
  • OK, so I will accept this answer. Maybe it also fits the original question better since the question actually was how to solve a certain problem under the assumption that oneside option is used.
    – lpdbw
    Aug 29, 2012 at 12:50
  • Could it be that the ifthen package has incompatibilies with other packages, e.g. etoolbox?
    – lpdbw
    Aug 29, 2012 at 12:51
  • @lpdbw I can't imagine that, because it's part of the LaTeX base. There might be issues with fragility in certain contexts, though. If you're having problems, there are lots of alternatives. I just wanted to use the "standard method". Aug 29, 2012 at 12:53
10

Inspired by Stefan Lehmke's comment I found the following solution:

  • Use twoside.
  • Add \renewcommand{\cleardoublepage}{\clearpage} to avoid that LaTeX forces chapters to start always on even pages (put at the end of the preamble).
  • Add the option asymmetric in the geometry package so that inner and outer marges are not swapped on alternate pages.

\documentclass{book}

\usepackage{lipsum}
\usepackage{fancyhdr}

\usepackage[
  a4paper,
  asymmetric,                               
  textwidth=16cm,
  outer=2cm,
  textheight=45\baselineskip,
  headheight=\baselineskip,
  includehead=true,% Default
  heightrounded,
]{geometry}

\pagestyle{fancy}
\fancyhead{}
\fancyhead[LO]{\leftmark}
\fancyhead[RE]{\rightmark}
\fancyhead[LE,RO]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\fancyfoot{}

\renewcommand{\cleardoublepage}{\clearpage}

\begin{document}

\chapter{Chapter One}
\section{Section One of Chapter One}
\lipsum
\lipsum
\section{Section Two of Chapter One}
\lipsum
\lipsum

\chapter{Chapter Two}
\section{Section One of Chapter Two}
\lipsum
\lipsum
\section{Section Two of Chapter Two}
\lipsum
\lipsum

\end{document}

You must log in to answer this question.

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