# Is there method for removing \\ newlines - problem with fancyhdr and multiline chapter name

Some of my chapter has very long names, and they have different break line in ToC and on Chapter page, according to a solution to How to make (force) line-break in Chapter Title (in ToC, Chapter, Header) - if possible?

The problem is that when I have such "multi-line" chapter name, it is broken in fancyhdr.

(For clarification : new lines are problem in fancydhr. In ToC and chapter names they are intentional and have to stay)

Is there a method for removing newlines \\, like \MakeUppercase for making letters uppercase ?

\documentclass[pdftex,a4paper,12pt,twoside,openany]{report}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}
\fancyfoot[C]{\thepage}
\begin{document}
\tableofcontents
\newcommand{\term}{\textit}
%\cleardoublepage \phantomsection
\chapter
[FIRST LONG LINE\\SECOND \textit{LONG} LINE\\THIRD LONG LINE\\FOURTH LONG LINE]
{FIRST LONG LINE\\SECOND \textit{LONG} LINE\\THIRD LONG LINE\\FOURTH LONG LINE}
\lipsum[1-60]
\end{document}


What I am looking for is a kind of macro \MakeNoNewlines that would be used in similar fashion as \MakeUppercase: is used :

\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ \MakeNoNewlines{#1}}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ \MakeNoNewlines{#1}}}

• Please provide a minimal working example showing at least one chapter that has a ToC and the headline. This should also load the necessary \documentclass. – Werner Feb 14 '12 at 23:16
• @Werner - Thanks, I alsways try to provide such. Yesterday I've been running out of time. Question updated with minimal example. – Grzegorz Wierzowiecki Feb 15 '12 at 12:32
• @GrzegorzWierzowiecki Such long titles won't fit in the header anyway. – egreg Feb 15 '12 at 12:44

Your \MakeNoNewlines command can be defined as in the following. We can locally redefine \\ to insert only a <space>. It doesn't help for the Table of contents though.

\documentclass[a4paper,12pt,twoside,openany]{report}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ \MakeNoNewlines{#1}}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ \MakeNoNewlines{#1}}}

\def\MakeNoNewlines#1{\begingroup\def\\{ }#1\endgroup} % <-- here

\renewcommand{\footrulewidth}{0pt}
\fancyhf{}

• It does not work in my case, as there are \textit{} in my chapter and section names. This results in error: Use of \protect doesn't match its definition. . I've updated MWE. – Grzegorz Wierzowiecki Feb 26 '12 at 20:38