I am using fancyhdr for the layout of my document, and it happens that my page numbers are in the margin, what I would like to avoid. Here is the output : Page numbers in the margin

Since the part of my header a priori concerning geometry and fancyhdr does work, since it does when I only include them in an other document, it should be hapening because of the other packages and settings. Could you help be to find the guilty command?

\documentclass[12pt, a4paper, twoside, openright]{book}


\usepackage[french, english]{babel}
\usepackage{amsfonts, amssymb, amsmath} 
\usepackage[all, cmtip]{xy}
\usepackage[linkcolor=blue, citecolor=green, colorlinks=true]{hyperref}

\renewcommand{\nomname}{List of Abbreviations and Symbols}

\usepackage{newtxtext, newtxmath}


{ \begin{itemize}
    \setlength{\parsep}{0pt}     }
{ \end{itemize}                  } 


%environnements mathématiques

\newenvironment{note}{\begin{minipage}{\dimexpr\linewidth - 1cm} \small \textsc{Note.}}{\end{minipage} \normalsize}
\newcommand{\didier}[1]{{\sf $\spadesuit\spadesuit\spadesuit$ Didier: [#1]}}
\newcommand{\ian}[1]{{\sf $ \clubsuit\clubsuit\clubsuit$ Ian: [#1]}}


\renewenvironment{note}{\begin{minipage}{\dimexpr\linewidth - 1cm} \small \textsc{Note.}}{\end{minipage} \normalsize}





    % Note the ## here. It's required because \fancypagestyle is making a macro (\ps@fancybook).
    % If we just wrote #1, TeX would think that it's the argument to \ps@fancybook, but
    % \ps@fancybook doesn't take any arguments, so TeX would complain with an error message.
    % You are not expected to understand this.
    \renewcommand*{\sectionmark}[1]{ \markright{\thesection\ ##1} }%
    \renewcommand*{\chaptermark}[1]{ \markboth{\chaptername\ \thechapter: ##1}{} }%
    % Increase the length of the header such that the folios 
    % (typography jargon for page numbers) move into the margin
    \fancyhfoffset[LE]{6mm}% slightly less than 0.25in
    % Put some space and a vertical bar between the folio and the rest of the header


\fancyhead[ro, le]{\thepage}



\usepackage[headsep=.25in, textheight=675pt]{geometry}

\renewcommand{\listtheoremname}{List of theorems}

  • Comment out the geometry package and the width fits. So that might be the faulty line. But there are other mistakes in this code. You should load hyperref last (there are some packages which should be loaded afterwards, but those should mention that in the documentation). You load fancyhdr twice and setup two pagestyles, no need for that. There might be others, but those I spotted quickly. – Skillmon likes topanswers.xyz Feb 20 '18 at 15:50
  • And why do you load lipsum? Do you display some dummy text in your document? – Skillmon likes topanswers.xyz Feb 20 '18 at 15:53
  • @Skillmon Thanks for the comment concerning hyperref, I changed it. Geometry was loaded later, in particular after the definition of the fancybook style, so I haven't thought in changing its place. Many thanks for your answer, it works with geometry loaded at the beginning. – Desiderius Severus Feb 20 '18 at 16:19
  • @Skillmon: The point is not the loading geometry itself, it is rather done untimely... it should be used before fancyhdr, since fancyhdr does not detect layout changes later on (at least it did not in the past) – user31729 Feb 20 '18 at 17:49
  • @ChristianHupfer see my "answer" or the comment by OP?! – Skillmon likes topanswers.xyz Feb 20 '18 at 19:24

As noted in the comment, you can solve this by loading geometry prior to fancyhdr and its settings.

| improve this answer | |

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.