2

I'm completely new to using headers and am struggling to understand the options of the packages I'm using.

I took this header setup from a friend:

\documentclass[11pt,onecolumn]{book}
\usepackage{geometry}
\usepackage{fancyhdr,textcase}

\pagestyle{fancy}

\fancyhead{}
\fancyhead[L]{\nouppercase\leftmark}
\fancyhead[R]{\nouppercase\rightmark}
\geometry{a4paper,inner=40mm,outer=15mm,top=15mm,bottom=15mm,footskip=5mm,headsep=3mm,headheight=15mm,twoside}

\begin{document}
\title{Some title}
\maketitle

\chapter{The first chapter}
some text!
\section{The first section}
Some more text!

\end{document}

This file is a {book}, and what I'd like is for the left-page header to give only the current chapter, and the right-page header to give only the current section.

However, the header is currently the same on both pages and shows both the chapter and the section.

I'm sure this is a simple fix, but I'm having trouble knowing where to look for info.

thanks!

  • Did you used twoside in documentclass option? i.e. \documentclass[twoside]{book}. – Jagath Jun 25 '16 at 17:27
  • @jagathAR I'm using twoside in the geometry package, but that's all as far as I can tell. I'll update the code in the question with more info on whats in the latex header. – CBowman Jun 25 '16 at 17:29
  • A minimal working example would be helpful. – Johannes_B Jun 25 '16 at 17:36
  • @johannes_B good point... I've now added something which compiles. You'll have to add some dummy text to add extra pages to see the header, though. – CBowman Jun 25 '16 at 17:54
4

Maybe you are looking for

\documentclass[11pt,onecolumn]{book}
\usepackage{geometry}
\usepackage{fancyhdr}

\geometry{a4paper,inner=40mm,outer=15mm,top=15mm,bottom=15mm,footskip=5mm,headsep=3mm,headheight=15mm,twoside}

\pagestyle{fancy}
\fancyhead{}
\fancyhead[LE]{\nouppercase\leftmark}% LE -> Left part on Even pages
\fancyhead[RO]{\nouppercase\rightmark}% RO -> Right part on Odd pages

\usepackage{blindtext}% dummy text
\begin{document}
\title{Some title}
\author{Author}
\maketitle
\blinddocument
\end{document}

Note that I have used \geometry before \pagestyle{fancy}.

enter image description here

  • Thanks, that did the trick. I had never considered that the ordering of things like \geometry{} in the preamble could be important! I'll have to watch out for that in future. – CBowman Jun 25 '16 at 19:17
1

Could you please check whether the following works for you:

\fancyhead{}
\fancyhead[LE,RO]{\nouppercase\leftmark}
\fancyhead[RE,LO]{\nouppercase\rightmark}

The MWE will now looks like:

\documentclass[11pt,onecolumn]{book}
\usepackage{geometry,lipsum}
\usepackage{fancyhdr,textcase}

\pagestyle{fancy}

\fancyhead{}
\fancyhead[LE,RO]{\nouppercase\leftmark}
\fancyhead[RE,LO]{\nouppercase\rightmark}
\geometry{a4paper,inner=40mm,outer=15mm,top=15mm,bottom=15mm,footskip=5mm,headsep=3mm,headheight=15mm,twoside}

\begin{document}
\title{Some title}
\maketitle

\chapter{The first chapter}
some text!
\section{The first section}
Some more text!

\lipsum\lipsum

\end{document}
  • Tried it and it doesn't seem to change anything unfortunately. Don't know if it matters but i did clean out all the auxiliary files after the change. – CBowman Jun 25 '16 at 17:44
  • 1
    Please add some text after \section{} and check next two pages. Add \usepackage{lipsum} in preamble and add \lipsum\lipsum after \section{} and check the pages. – Jagath Jun 25 '16 at 17:46
  • 2
    @JagathAR: While this might be solution anyone seeing it has to build up a compilable document of this fragment -- this is not our preferred way of answering questions ;-) – user31729 Jun 25 '16 at 17:49
  • 1
    @ChristianHupfer. Sorry. I have now put the MWE. – Jagath Jun 25 '16 at 17:52
  • 2
    @JagathAR: The TeX.SX force is strong in you ;-) (+1) – user31729 Jun 25 '16 at 17:53

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.