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:


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

\fancyhf{}                              % delete the current header and footer


\fancyhead{}                            % get rid of the headers on plain pages
\renewcommand{\headrulewidth}{0pt}      % and the line
  • You can use \markboth{}{}. You will find a lot of examples at tex stackexchange. – Marco Daniel Mar 21 '12 at 19:24
  • multi-line running heads aren't usually a good idea. \markboth with a shorter form for the running head would be better. – barbara beeton Mar 21 '12 at 19:40
  • @MarcoDaniel thanks. I searched round (and elsewhere), and experimented, but can't get what I want. I've edited my question to show the preamble I'm using (book class, oneside). – Chris Poole Mar 21 '12 at 20:15
  • @barbarabeeton could you explain in more detail what you mean please? I tried changing \markright to \markboth when renewing the \sectionmark command, to no avail. – Chris Poole Mar 22 '12 at 12:20
  • Headers on left pages are easily fixable. \fancyhead[LO]{\textbf{\rightmark} \phantom{aaa}}. Unfortunately, I haven't been able to use the same trick to fix right pages. – Rufo Jan 6 '17 at 23:19

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}

Put your fancy head in LO inside a parbox as shown below:

\fancyhf{}                              % delete the current header and footer
\fancyhead[LO]{\parbox{0.7\textwidth}{\textbf{\rightmark}}}% <----\parbox here.

And do not use \\ in short title: \section[really long section\\name]{really long section name}

EDIT: You may use

\fancyhf{}                              % delete the current header and footer
\fancyhead[LO]{\parbox[t]{0.9\textwidth}{\textbf{\rightmark}}} %<--- use [t] for parbox.
\fancyhead[RO]{\parbox[t]{0.02\textwidth}{\textbf{\thepage}}} %<--- better use [t]  here also for parbox to ensure that alignment.

Also to adjust the head separation you can use

\setlength{\headsep}{0.25in} % <---change the value accordingly

enter image description here

  • Thanks. That did work (also for 0.95 * textwidth), but unfortunately it moves all headings slightly (perhaps 3/8 em or something) down, relative to the page number. – Chris Poole Mar 22 '12 at 12:18
  • @ChrisPoole, I have edited the answer accordingly. – user11232 Mar 22 '12 at 13:39

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.