Here's the MWE:
\documentclass[a4paper,twoside=true,11pt,openright]{book}
% packages:
\usepackage{blindtext}
\usepackage{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\addtolength{\headwidth}{\marginparsep}
\addtolength{\headwidth}{\marginparwidth}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\fancyhf{}
\fancyhead[RO]{\rightmark}
\fancyhead[LE]{\leftmark}
\fancyfoot[RO,LE]{\thepage}
\renewcommand{\headrulewidth}{1pt}
\begin{document}
\blinddocument
\end{document}
Here's what the document looks like, the header (and footer) goes outside the page. I would like both of them to extend slightly beyond the text width.
geometry
changes the page layout and enlargesmarginparwidth
. You can remove the package or load it with optionpass
(disables all of the geometry options and calculations exceptverbose
andshowframe
) or you adjustmarginparwidth
to ensure that the marginpar does not go outside of the paper: eg.\usepackage[marginparwidth=2cm]{geometry}
.fancyhdr
is not the only way to customise headers and footers:titleps
, which is a companion package oftitlesec
, has awidenhead(*)
command.fancyhdr
way to enlarge the header/footer width would be\fancyhfoffset[LE,RO]{1cm}
. It extends to the left on even and to the right on odd pages. See the documentation.