0

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

\newcommand{\makemargins}{
\makenomenclature
\pagestyle{fancy}
\fancyheadoffset{1cm}
\setlength{\headheight}{2cm}
\lhead{\includegraphics[width=0.25\textwidth]{./logos/logo.pdf}} % Set image at top of the page
\rhead{\nouppercase{\rightmark}}
\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:

enter image description here

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

MWE added:

\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}
\fancyheadoffset{1cm}
\setlength{\headheight}{2cm}
\lhead{\includegraphics[width=0.15\textwidth]{example-image-a}} % Set image at top of the page
\rhead{\nouppercase{\rightmark}}
}

\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}
  • 1
    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
  • 1
    I don't get any section name in the header if I compile your example – ufo 2 days ago
1

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}
\fancyheadoffset{1cm}
\setlength{\headheight}{2cm}
\lhead{\includegraphics[width=0.15\textwidth]{example-image-a}} % Set image at top of the page
\rhead{\begin{minipage}[b]{15cm}\nouppercase{\rightmark}\end{minipage}}
}

\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}

enter image description here

(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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.