Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\setlength{\headheight}{15pt}
\setlength{\headsep}{8pt}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}
\fancyhead[RO]{\rightmark}
\fancyhead[LE]{\leftmark}
\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}}}
share|improve this question
3  
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

1 Answer 1

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}
\setlength{\headheight}{15pt}
\setlength{\headsep}{8pt}
\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{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}
\fancyhead[RO]{\rightmark}
\fancyhead[LE]{\leftmark}
\fancyfoot[C]{\thepage}
\begin{document}
\tableofcontents
\newcommand{\term}{\textit}
%\cleardoublepage \phantomsection
\chapter
[FIRST LONG LINE\\SECOND LONG LINE\\THIRD LONG LINE\\FOURTH LONG LINE]
{FIRST LONG LINE\\SECOND LONG LINE\\THIRD LONG LINE\\FOURTH LONG LINE}
\lipsum[1-60]
\end{document}
share|improve this answer
    
newlines in ToC are fine. They are only problem in fancyhdr. In first free moment I will checkout your solution with my document. –  Grzegorz Wierzowiecki Feb 15 '12 at 15:06
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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