[Tex/LaTex] (Book) Page number at new chapter is centered, but it shouldn’t be

booksfancyhdrheader-footerpage-numbering

I have the following problem:

\documentclass[a4paper]{book}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx} 
\usepackage{dsfont}
\usepackage{tikz}
\usepackage{braket}
\usepackage[figurename=Fig., font={footnotesize}]{caption}
\usepackage{float}
\usepackage{placeins}
\usepackage{epstopdf}
\usepackage[a4paper,left=40mm, right=40mm ,top=35mm,bottom=35mm]{geometry}
\usepackage{subfig}
\usepackage{tabularx}
\epstopdfsetup{outdir=./}
\usepackage{tikz-feynman, contour}
\usepackage[toc,title]{appendix}
\usepackage[nottoc]{tocbibind}
\usepackage[parfill]{parskip}
\usepackage{mathtools}
\usepackage[square, numbers, comma, sort&compress]{natbib} 
\captionsetup[figure]{labelfont=bf}
\usepackage{hyperref}

\makeatletter
\@addtoreset{footnote}{section}
\makeatother

\renewcommand\vec{\boldsymbol}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LO]{{\rightmark}}
\fancyhead[RE]{{\leftmark}}
\fancyfoot[RO,LE]{\thepage}

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\usepackage{chngcntr}
\counterwithout{figure}{chapter}

This is everything I have before I start the document. The problem I have now, is: every time I start a new chapter, the page number appears at the bottom of the page in the center, but the way I set it up (and want it to be) is that it should appear either left or right (depending on even/odd page number). I cannot find the error. Before, this was not a book, but an article and there it worked the way I wanted it. Now I changed it to book and left the rest the way it was before. Everything else works fine, its just the starting page of each chapter.

I hope my information is sufficient for you to find the error.

In addition, it would be nice, if I could keep my footer even if a new chapter starts on this page (the header can vanish as it usually does with new chapters).

Edit: Now that is weird. I thought the commands would line up beneath each other, but they don't. Really sorry for that, gonna see if I can fix it up.

Best Answer

The problem comes from the fact that, in the book class, the first page of a chapter uses the plain style. The solution consists in redefining the plain style with fancyhdr. Here is a code, adapted from the documentation:

\fancypagestyle{plain}{%
\fancyhf{}% clears all header and footer fields
\fancyhead[LE,RO]{\thepage}%
\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{0.4pt}}