1

I use a template with a documentclass{book} for my thesis, but for some reson the page numbering is messed up, in some pages numbers are in the middle of the page (as it should be) and in some pages, they are at the top of the page. So I fixed this with \usepackage{fancyhdr} and \pagestyle{fancy}, but now headers are messed, for example: enter image description here Here is a "main.tex" code example:

\documentclass[12pt,a4paper,oneside,onecolumn]{book}
\usepackage[letterpaper, portrait]{geometry}
\usepackage{lipsum}
%SET AVERAGE MARGIN
\geometry{
left={4cm},
right={2cm},
top={1.5cm},
bottom={2.5cm},
}
\usepackage{layout}
\usepackage{fancyhdr}
\usepackage{libertine}
\usepackage{courier}
\usepackage[utf8x]{inputenc}
\usepackage[hebrew,english]{babel}
\usepackage[longnamesfirst,square,numbers,comma,sort&compress]{natbib}
\usepackage{titlesec}
\usepackage{float}
\usepackage{graphicx,caption}
\usepackage{amsmath}
\usepackage{mathpazo}
\usepackage{datetime}
\usepackage{hyperref}
\usepackage{bookmark}
%
\usepackage{float}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{eufrak} 
\usepackage{accents} 
\usepackage{mathtools}
\usepackage{nicematrix}



\newcommand*{\bfrac}[2]{\genfrac{\lbrace}{\rbrace}{0pt}{}{#1}{#2}} %bar free fraction
\usepackage{romannum} %Roman numerals
\usepackage{bm}
%\addbibresource{ref.bib} %Imports bibliography file

\setlength{\parindent}{0pt}
\setlength{\parskip}{5pt}

\titleformat{\chapter}[hang]{\bf\huge}{\thechapter}{2pc}{}
\title{Thesis Template}

\begin{document}
%\layout


\include{cover}
\include{cover_heb}
\include{cover_sig}

\frontmatter
\pagestyle{fancy}

\include{Chapters/abstract_heb}
\include{Chapters/abstract}
\include{Chapters/table_of_abb}
\include{Chapters/acknowledgements}

\tableofcontents
\include{Chapters/table_of_symbols}
\listoffigures
\listoftables


\mainmatter
\pagestyle{fancy}

\input{Chapters/introduction}
\input{Chapters/previous_work}
\input{Chapters/Metasurface_analysis}
\input{Chapters/research_question}
\input{Chapters/methods}
\input{Chapters/results}
\input{Chapters/conclusion}

\section{}
\bibliographystyle{IEEEtran}
\bibliography{ref}

\end{document}

Any help is appreciated.

5
  • It would be helpful if you could provide a compilable minimal working example (MWE) that does not rely on multiple external files not accessible to others. You mention wanting to get the page number centered in the footer on all pages. But what about the header? Do you want any contents (chapter number/name) there, as well? If you want an empty header, you could try \pagestyle{plain}.
    – leandriis
    Commented Jul 3, 2021 at 8:57
  • 1
    Regarding your description "for some reson the page numbering is messed up, in some pages numbers are in the middle of the page (as it should be) and in some pages, they are at the top of the page": This is not reandom, but due to the book class using a different page style for first pages of a chapter and all other pages.
    – leandriis
    Commented Jul 3, 2021 at 9:02
  • If I understand correctly, the name of the section inside chapter 3 is too long, which is "\section{Multilayer metasurface modeling}". Commented Jul 3, 2021 at 9:04
  • What would you like to change about that? Do you want to keep the section heading in the page header, but in a shortened form or do you want to entirely remove it from the page header? Do you want to alter the font size or do you want to allow line breaks?
    – leandriis
    Commented Jul 3, 2021 at 9:08
  • I think I want only the name of the chapter in the left . Commented Jul 3, 2021 at 9:14

1 Answer 1

1

Something like this (that the added code is commanted with %here) could solve your problems (about the header).

\documentclass[12pt,a4paper,oneside,onecolumn]{book}
\usepackage[letterpaper, portrait]{geometry}
\usepackage{lipsum}
%SET AVERAGE MARGIN
\geometry{
left={4cm},
right={2cm},
top={1.75cm}, %here
bottom={2.5cm},
head={1.5cm}, %here
includehead %here
}
\usepackage{layout}
\usepackage{fancyhdr}
\usepackage{libertine}
\usepackage{courier}
\usepackage[utf8x]{inputenc}
\usepackage[hebrew,english]{babel}
\usepackage[longnamesfirst,square,numbers,comma,sort&compress]{natbib}
\usepackage{titlesec}
\usepackage{float}
\usepackage{graphicx,caption}
\usepackage{amsmath}
\usepackage{mathpazo}
\usepackage{datetime}
\usepackage{hyperref}
\usepackage{bookmark}
%
\usepackage{float}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{eufrak} 
\usepackage{accents} 
\usepackage{mathtools}
%\usepackage{nicematrix}
\fancyhead[l]{} %here
\fancyhead[r]{} %here
\fancyhead[c]{\parbox[b]{\textwidth}{\parbox[b]{0.45\linewidth}{\rightmark}\hspace{\fill}\parbox[b]{0.45\linewidth}{\null\hfill\leftmark}}} %here

\newcommand*{\bfrac}[2]{\genfrac{\lbrace}{\rbrace}{0pt}{}{#1}{#2}} %bar free fraction
\usepackage{romannum} %Roman numerals
\usepackage{bm}
%\addbibresource{ref.bib} %Imports bibliography file

\setlength{\parindent}{0pt}
\setlength{\parskip}{5pt}

\titleformat{\chapter}[hang]{\bf\huge}{\thechapter}{2pc}{}
\title{Thesis Template}

\begin{document}
%\layout


\include{cover}
\include{cover_heb}
\include{cover_sig}

\frontmatter
\pagestyle{fancy}


\tableofcontents

\listoffigures
\listoftables


\mainmatter
\pagestyle{fancy}

\chapter{A Chapter}
\section{A section with a big name}
\newpage
\section{Another section with a much bigger name}


\end{document}

EDIT

In order to remove the section header and keep only the chapters, try like this instead: (Some un-needed code but this way you will be flexible in changes)

\fancyhead[c]{\parbox[b]{\textwidth}{\leftmark}} %here

6
  • I got the idea, it is better, but still not good, is there a way to put the name of the chapter only, without a section? Commented Jul 3, 2021 at 9:13
  • @MichaelElman: See edit please.
    – koleygr
    Commented Jul 3, 2021 at 9:16
  • Perfect, thanks! Commented Jul 3, 2021 at 9:18
  • 1
    @koleygr: What about \fancyhead[l]{\leftmark} \fancyhead[r]{}?
    – leandriis
    Commented Jul 3, 2021 at 9:19
  • Welcome and Happy TeXing!
    – koleygr
    Commented Jul 3, 2021 at 9:19

You must log in to answer this question.

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