Is it possible to change the font size of the section number and text with fancyhdr

fancyhdrsectioningtitlesec

We would like to change the font size of the section only, but as header and footer is set with fancyhdr, then we would like to use same package or a package that is not in conflict with fancyhdr. Our section and sub section looks like the following:

enter image description here

We would like it to look like the following:

enter image description here

Above is achieved with the titlesec package, but unfortunately that is in conflict with fancyhdr, and everything we have made with fancyhdr messes up whenever we try to use titlesec. Therefore, it is highly preferred to change the section font size in fancyhdr, as we do not wish to convert all the things we have written with fancyhdr to titlesec.

\titleformat{\section}{\bfseries\LARGE}{\hspace{1ex}\Huge\thesection}{2ex}{}

Following is the main file:

\documentclass[11pt, report]{report}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\graphicspath{ {./figures/} }
\usepackage{lastpage}
\usepackage{array}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage{fancyhdr} 
\usepackage{color}
%\usepackage[pagestyles]{titlesec} % <------ changed
\usepackage{hyperref}
\usepackage{lastpage,refcount,atbegshi}
\usepackage{lipsum}

\title{Header}   % Title
\author {Ahmad Ahmadsen} % Author
\date{\today} % Date

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy} 
\fancyhf{} 
\lhead{\thetitle} 

\rfoot{\thepage \space} 
\lfoot{University} 

\begin{document}

\cfoot{\thepage \space of \pageref{LastPage}}
\rfoot{} 
\lfoot{} 

\renewcommand \thesection{\arabic{section}}

% Add sections here!
\section{Introduction}
\subsection{Motivation}
\subsection{Research Question}

\section{Analysis}
\subsection{analys 1}
\subsection{analys 2}
\subsection{analys 3}

\end{document}

Best Answer

titlesec uses macros that fancyhdr is also using. This is why if you put \usepackage{titlesec} after \usepackage{fancyhdr} you get errors. \usepackage{titlesec} to before \usepackage{fancyhdr}.

Also as @Buster3650 noted, titlesec defines \thetitle so it would be best to define a different name to be used in the header.

If you want ALL your sections to be the same, here is is in your MWE

\documentclass[11pt, report]{report}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\graphicspath{ {./figures/} }
\usepackage{lastpage}
\usepackage{array}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}

\usepackage[pagestyles]{titlesec} % <------ This here 
\titleformat{\section}{\bfseries\LARGE}{\hspace{1ex}\Huge\thesection}{2ex}{} %<--- and this

\usepackage{fancyhdr} %<---- Before that there
\usepackage{color}
\usepackage{hyperref}
\usepackage{lastpage,refcount,atbegshi}
\usepackage{lipsum}

\title{Header}   % Title
\author {Ahmad Ahmadsen} % Author
\date{\today} % Date

\makeatletter
\let\mytitle\@title %<--- changed
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy} 
\fancyhf{} 
\lhead{\mytitle} %<--- changed

\rfoot{\thepage \space} 
\lfoot{University} 

\begin{document}

\cfoot{\thepage \space of \pageref{LastPage}}
\rfoot{} 
\lfoot{} 

\renewcommand \thesection{\arabic{section}}

% Add sections here!
\section{Introduction}
\subsection{Motivation}
\subsection{Research Question}

\section{Analysis}
\subsection{analys 1}
\subsection{analys 2}
\subsection{analys 3}

\end{document}

This also works if you want to start with this format at a certain point

\documentclass[11pt, report]{report}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\graphicspath{ {./figures/} }
\usepackage{lastpage}
\usepackage{array}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}

\usepackage[pagestyles]{titlesec} % <------ This

\usepackage{fancyhdr} % <---- Before That
\usepackage{color}
\usepackage{hyperref}
\usepackage{lastpage,refcount,atbegshi}
\usepackage{lipsum}

\title{Header}   % Title
\author {Ahmad Ahmadsen} % Author
\date{\today} % Date

\makeatletter
\let\mytitle\@title %<--- changed
\let\theauthor\@author
\let\thedate\@date
\makeatother

\pagestyle{fancy} 
\fancyhf{} 
\lhead{\mytitle} %<--- changed

\rfoot{\thepage \space} 
\lfoot{University} 

\begin{document}

\cfoot{\thepage \space of \pageref{LastPage}}
\rfoot{} 
\lfoot{} 

\renewcommand \thesection{\arabic{section}}

% Add sections here!
\section{Introduction}
\subsection{Motivation}
\subsection{Research Question}

\titleformat{\section}{\bfseries\LARGE}{\hspace{1ex}\Huge\thesection}{2ex}{} %<--- Now this works
\section{Analysis}
\subsection{analys 1}
\subsection{analys 2}
\subsection{analys 3}

\end{document}
Related Question