2

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. enter image description here

4
  • 1
    Loading package geometry changes the page layout and enlarges marginparwidth. You can remove the package or load it with option pass (disables all of the geometry options and calculations except verbose and showframe) or you adjust marginparwidth to ensure that the marginpar does not go outside of the paper: eg.\usepackage[marginparwidth=2cm]{geometry}.
    – esdd
    Oct 26, 2021 at 18:45
  • fancyhdr is not the only way to customise headers and footers: titleps, which is a companion package of titlesec, has a widenhead(*) command.
    – Bernard
    Oct 26, 2021 at 19:28
  • @esdd Thanks your last suggestion with 1cm instead of 2cm did the exact job I wanted! Oct 26, 2021 at 19:37
  • 2
    For completeness: The 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. Oct 26, 2021 at 21:40

1 Answer 1

1

Two little changes to your MWE and you are done:

\documentclass[a4paper,twoside=true,11pt,openright]{book}

% packages:
\usepackage{blindtext}
\usepackage{geometry}
\usepackage{fancyhdr}

\pagestyle{fancy}
\addtolength{\headwidth}{.5cm}
\addtolength{\headwidth}{.5cm}
\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}

enter image description here

3
  • You could reduce the 2 lines \addtolength{\headwidth}{.5cm} to one line \addtolength{\headwidth}{1cm}.
    – dexteritas
    Oct 27, 2021 at 14:37
  • @desteritas Yes commment the first line (%) and change 0.5cm in 1cm in the second one. You will have 1 cm more heather on even pages and 1 cm more heather on odd pages. Oct 27, 2021 at 14:46
  • Yes you can have this: %\addtolength{\headwidth}{.5cm} \addtolength{\headwidth}{1cm} Oct 27, 2021 at 15:06

You must log in to answer this question.

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