# Page numbering in the margin with fancyhdr

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 :

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}

\title{}
\author{}
\date{}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french, english]{babel}
\usepackage{amsfonts, amssymb, amsmath}
\usepackage{color}
\usepackage{graphicx}
\usepackage[all, cmtip]{xy}
\usepackage{amsthm}
\usepackage{stmaryrd}
\usepackage{appendix}
\usepackage{scrextend}
\usepackage{lipsum}
\usepackage{array}
\usepackage{makeidx}
\usepackage[Lenny]{fncychap}
\makeindex
\usepackage{minitoc}
\usepackage{enumitem}
\usepackage[intoc]{nomentbl}

\makenomenclature
\renewcommand{\nomname}{List of Abbreviations and Symbols}
\setlength{\nomitemsep}{-\parsep}
\usepackage{titlesec}
\newcolumntype{L}{>{$}c<{$}}
\numberwithin{equation}{section}
\allowdisplaybreaks

\usepackage{newtxtext, newtxmath}
\usepackage{fullpage}

\setlength{\footskip}{1.95cm}
\setlength{\parindent}{1em}
\setlength{\parskip}{0em}

\newenvironment{myitemize}
{ \begin{itemize}
\setlength{\itemsep}{0pt}
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}     }
{ \end{itemize}                  }

\newcommand{\nocontentsline}[3]{}

%environnements mathématiques
\theoremstyle{plain}
\newtheorem{thm}{Theorem}
\newtheorem{mythm}{Theorem}
\newtheorem{coro}[mythm]{Corollary}
\renewcommand*{\themythm}{\Alph{mythm}}
\newtheorem{mythmfr}{Théorème}
\renewcommand*{\themythmfr}{\Alph{mythmfr}}
\newtheorem{corofr}[mythmfr]{Corollaire}
\newtheorem{lem}{Lemma}
\newtheorem{prop}{Proposition}
\newtheorem{conj}{Conjecture}
\newtheorem{myconj}{Conjecture}
\renewcommand*{\theconj}{\Alph{myconj}}
\newtheorem{myconjfr}{Conjecture}
\renewcommand*{\themyconjfr}{\Alph{myconjfr}}
\newtheorem{pb}{\textbf{Problem}}
\theoremstyle{definition}
\newtheorem{defi}{Definition}
\theoremstyle{plain}
\newtheorem{thmfr}{Théorème}
\newtheorem{lemfr}{Lemme}
\newtheorem{propfr}{Proposition}
\newtheorem{conjfr}{Conjecture}
\newtheorem{pbfr}{\textbf{Problème}}
\theoremstyle{definition}
\newtheorem{defifr}{Définition}

\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]}}

\usepackage{fancyhdr}
\pagestyle{plain}

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

%\numberwithin{equation}{chapter}

\usepackage{chngcntr}
\counterwithout{equation}{section}
\renewcommand{\theequation}{\thechapter.\arabic{equation}}

\setcounter{minitocdepth}{1}

\usepackage{tocloft}
%
\setlength\cftparskip{1pt}
\setlength\cftbeforechapskip{5pt}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancypagestyle{fancybook}{
\fancyhf{}%
% 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
\fancyhfoffset[RO]{6mm}%
% Put some space and a vertical bar between the folio and the rest of the header
}

\makeatletter
\let\@oddfoot\@empty
\let\@evenfoot\@empty
\makeatother

\usepackage{longtable}

\dominitoc
\titleformat*{\subsubsection}{\normalsize\itshape}
\usepackage{thmtools}
\renewcommand{\listtheoremname}{List of theorems}

\begin{document}

• 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.