# Break line of long header with pagestyle fancy

I have a class where I define headers and footers with a makemargins command:

\newcommand{\makemargins}{
\makenomenclature
\pagestyle{fancy}
\lhead{\includegraphics[width=0.25\textwidth]{./logos/logo.pdf}} % Set image at top of the page
\rfoot{\thepage}
\cfoot{\textbf{\reporttitle}}
\lfoot{\coursecode}
}

However, when the section title that defines my right header is very long I get into troubles because the text overlaps with the logo in the left header, like in the following image:

How can I set a maximum horizontal size to the right header in such a way that long texts are automatically broken in more lines?

EDIT

\documentclass[a4paper,12pt]{article}
%--------------------- General Packages ------------------------
\usepackage[english]{babel} % Language of the document
\usepackage{graphicx} % Insert figures
\usepackage{fancyhdr}

% Page configuration
\usepackage{geometry}
\geometry{a4paper,hscale=0.75,vscale=0.8}

% Package for references with numbers
\bibliographystyle{apsrev4-1}
\usepackage[numbers]{natbib}
\setcitestyle{numbers}

% Command for settings of headers and footers
\newcommand{\makemargins}{
\pagestyle{fancy}
\lhead{\includegraphics[width=0.15\textwidth]{example-image-a}} % Set image at top of the page
}

\begin{document}
\makemargins
\tableofcontents
\newpage
\section{Very very very very very very very very very very very very very very very long section 1}
\end{document}

By the way, if I remove from the above MWE the part related to the blibliography (see below), the section title disappears from the right header (using Overleaf). Why does that happens? I would assume that whatever I set for the bibliography has no relation with the headers and footers.

% Package for references with numbers
\bibliographystyle{apsrev4-1}
\usepackage[numbers]{natbib}
\setcitestyle{numbers}
• see if using short version of section or hapter` for example \section[<short version for headers and TOC>]{<long title version for the main text>} – Zarko Apr 15 at 14:28
• I don't get any section name in the header if I compile your example – ufo 2 days ago

With the help of a minipage:

\documentclass[a4paper,12pt]{book}
%--------------------- General Packages ------------------------
\usepackage[english]{babel} % Language of the document
\usepackage{graphicx} % Insert figures
\usepackage{fancyhdr}

% Page configuration
\usepackage{geometry}
\geometry{a4paper,hscale=0.75,vscale=0.8}

% Package for references with numbers
\bibliographystyle{apsrev4-1}
\usepackage[numbers]{natbib}
\setcitestyle{numbers}

% Command for settings of headers and footers
\newcommand{\makemargins}{
\pagestyle{fancy}
\lhead{\includegraphics[width=0.15\textwidth]{example-image-a}} % Set image at top of the page
}

\begin{document}
\makemargins
\tableofcontents
\newpage
\section{Very very very very very very very very very very very very very very very long section 1}

\newpage

x

\section{section 1}

\newpage

x
\end{document}

(I had to replace the documentclass, because there where no section titles in the header with the one from the question)

New contributor
ufo is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.