[Tex/LaTex] section title and page number overlapping in heading; fancyhdr

fancyhdrheader-footer

I have set the headings to show the section number and name on the left side of the page, and the page number on the right.

This works fine for most section names, but one particular one is a little long, but not long enough (it seems): it just overlaps the page number, but not enough to make LaTeX wrap automatically. (I have a longer heading and LaTeX notices this and does the right thing.)

I changed the section name to

\section[really long section\\name]{really long section name}

which works in the header fine, but (obviously) also makes a newline in the TOC. The section name fits the TOC fine, so:

Is it possible to force a newline in the header, but not the TOC entry?

This is how my preamble looks:

\usepackage{fancyhdr}
\pagestyle{fancy}

% with this we ensure that the Chapter and Section
% headings are in lowercase
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}{}}

\fancyhf{}                              % delete the current header and footer
\fancyhead[LO]{\textbf{\rightmark}}
\fancyhead[RO]{\textbf{\thepage}}

\renewcommand{\headrulewidth}{0pt}

\fancypagestyle{plain}{
\fancyhead{}                            % get rid of the headers on plain pages
\renewcommand{\headrulewidth}{0pt}      % and the line
\fancyfoot[R]{\textbf{\thepage}}
}

Best Answer

Instead of using \\ create a new macro with, say, \DeclareRobustCommand\NL{ } and redefine it locally in the headers with \DeclareRobustCommand\NL{\\}. Then write:

\section[really long section\NL name]{really long section name}
Related Question