[Tex/LaTex] Fancyhdr header and footer disappear

articlefancyhdrheader-footer

Just as it says in the title, my header and footer randomly disappear after my second numbered page.

This is my preamble:

% !TeX spellcheck = hr_HR
\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[
 backend=bibtex      % biber or bibtex
,style=numeric-comp  % numerical-compressed
,sorting=none        % no sorting
,sortcites=true      % some other example options ...
,block=none
,indexing=false
,citereset=none
,isbn=true
,url=true
,doi=true            % prints doi
,natbib=true         % if you need natbib functions
]{biblatex}

\addbibresource{bibliografija.bib}
\nocite{*}

\usepackage{fancyhdr}
\usepackage{indentfirst}
\usepackage{setspace}
\usepackage[croatian]{babel}

\ifx\l@croatian\@undefined
    \@nopatterns{Croatian}
    \adddialect\l@croatian0\fi

\captionscroatian

\usepackage{graphicx}
\graphicspath{ {img/} }

\renewcommand{\contentsname}{Sadržaj}

\title{MVC arhitektura unutar AngularJS razvojnog okvira}
\author{Marko Klobučar}
\date{Lipanj, 2017.}

The commands I issued to start the header and footer are as follow:

\pagestyle{fancy}
\fancyhf{}

\lhead{Sveučilište Sjever - Multimedija, oblikovanje i primjena}
\rhead{Marko Klobučar}
\rfoot{Stranica \thepage~od~\pageref{lastpage}}

\pagenumbering{arabic}

And all is well for a whole two pages. And then suddenly the header and footer vanish on my 6th actual, but 3rd numbered page.

I am terribly sorry if this has been answered before, I searched for an hour now and I couldn't find what I was looking for. I am also a complete beginner with Latex, and would appreciate any help.

Thank you in advance! Please, let me know if I should include something I forgot.

EDIT: Here's the small-ish document.

% !TeX spellcheck = hr_HR
\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
%\usepackage[
% backend=bibtex
%]{biblatex}

% \addbibresource{bibliografija.bib}
% \nocite{*}

\usepackage{fancyhdr}
\usepackage{indentfirst}
\usepackage{setspace}
\usepackage[croatian]{babel}

\ifx\l@croatian\@undefined
    \@nopatterns{Croatian}
    \adddialect\l@croatian0\fi

\captionscroatian

\usepackage{graphicx}
\graphicspath{ {img/} }

\renewcommand{\contentsname}{Sadržaj}

\title{Title}
\author{Me}
\date{Now}

\begin{document}

\pagestyle{empty}
\pagenumbering{gobble}

\begin{titlepage}
    \maketitle
\end{titlepage}

\newpage
\tableofcontents
\newpage

\begin{spacing}{1.5}
\section*{Lorem ipsum.}
Lorem ipsum.

\newpage

\pagestyle{fancy}
\fancyhf{}

\lhead{Header left}
\rhead{John Doe}
\rfoot{Page \thepage~of~\pageref{lastpage}}

\pagenumbering{arabic}

\section{Sažetak}
Lorem ipsum dolor sit amet.
\newpage

\section{Uvod}
Lorem ipsum dolor sit amet.
\newpage

\section{Trouble!}
\subsection{This part is messed up.}
This section is where the header and footer disappear.

\subsection{Lorem ipsum.}
Lorem ipsum.

\end{spacing}
\newpage

\section{Popis literature}
\label{lastpage}
\vspace*{-1cm}
% \printbibliography[title=~]

\end{document}

Best Answer

Here are two possible simple codes:

  • Either you use the {spacing}{1.5} environment, and you have to put the last \newpage command just before \end{spacing}, and repeat \pagestyle{fancy} right after,
  • Or you use the \onehalfspacing command, and replace \end{spacing} with \singlespacing.

Here are the codes for the relevant part:

With the environment:

\begin{spacing}{1.5}
\section*{Predgovor}
Here's some text.

\newpage
\pagestyle{fancy}
\pagenumbering{arabic}

\section{Sažetak}
Lorem ipsum dolor sit amet.
\newpage

\section{Uvod}
Lorem ipsum dolor sit amet.
\newpage

\section{O tehnologiji}
\subsection{O pojmu arhitekture u softverskom razvoju}
Here's some text.

\subsection{Opis MVC arhitekture}
Here's some text.
\newpage
\end{spacing}

\pagestyle{fancy}

\section{Popis literature}
\label{lastpage}
\vspace*{-1cm}
\printbibliography[title=Bib]

With the commands:

\onehalfspacing

\section*{Predgovor}
Here's some text.
\newpage
\pagestyle{fancy}
\pagenumbering{arabic}

\section{Sažetak}
Lorem ipsum dolor sit amet.
\newpage

\section{Uvod}
Lorem ipsum dolor sit amet.
\newpage

\section{O tehnologiji}
\subsection{O pojmu arhitekture u softverskom razvoju}
Here's some text.

\subsection{Opis MVC arhitekture}
Here's some text.

\newpage
\singlespacing

\section{Popis literature}
\label{lastpage}
\vspace*{-1cm}
\printbibliography[title=Bib]

enter image description here

Related Question