2

I am writing my master's thesis and would like to have my headers as in this book. I would like my even pages with the page number in the left margin and the chapter aligned to the left. My odd pages should have the page number in the right margin, and the section number aligned to the right.

Somewhat opposite to the example presented in the fancyhdr manual (p. 13):

\documentclass{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{calc}
\fancyheadoffset[LE,RO]{\marginparsep+\marginparwidth}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\fancypagestyle{plain}{%
    \fancyhead{} % get rid of headers
    \renewcommand{\headrulewidth}{0pt} % and the line
}

However, I am unable to edit this code to my liking, after having fiddled with it for an hour. Can you guys and gals help a fella out?

Left page:

Left page.

Right page:

Right page.

  • So you'd like that the chapter title on even pages is aligned with the left margin of the text block, and the section title flush with the right margin of the text block? – egreg Jun 4 '13 at 20:14
  • Yup, I added images explaining what I want too, see my question again! – Viktor Jun 4 '13 at 20:24
2

The offset you're using seems too much; but that's irrelevant. Here's a way: just tell LaTeX that you want to reserve for the page number the exact amount of the offset.

Using a parameterized length ensures that changes, if any, are made in only one place, namely where you set the \pageoffset parameter.

\documentclass{book}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{calc}
\newlength{\pageoffset}
\setlength{\pageoffset}{2cm}% use whatever you like
\fancyheadoffset[LE,RO]{\pageoffset}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\fancyhf{}
\fancyhead[LE]{\makebox[\pageoffset][l]{\bfseries\thepage}\bfseries\leftmark}
\fancyhead[RO]{\bfseries\rightmark\makebox[\pageoffset][r]{\bfseries\thepage}}
\fancypagestyle{plain}{%
    \fancyhead{} % get rid of headers
    \renewcommand{\headrulewidth}{0pt} % and the line
}

\usepackage{kantlipsum}
\begin{document}
\mainmatter
\chapter{Chapter title}
\section{Section title}
\kant[1-15]
\end{document}

Even page

enter image description here

Odd page

enter image description here

  • I think that was exactly what I needed, thank you! – Viktor Jun 4 '13 at 20:38

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.