# What is the difference between \\ and \linebreak in cfoot

\documentclass[a5paper,10pt]{article}
\usepackage{array,tabularx,longtable,tabu}
\usepackage{colortbl,tikz}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\cfoot{
\hrule
\vspace{1mm}
{ \footnotesize %
This is line one with some text. \linebreak % Replace \linebreak with \\ here to reproduce the error
This is line two with some more text.}}

\begin{document}

\begingroup
\footnotesize
\begin{longtabu} to \textwidth {Xrlrr}
\rowfont{\bfseries}
Name %
& \multicolumn{2}{c}{Qty}
& Price  %
& NET
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
\end{longtabu}
\endgroup
\end{document}


The above example compiles fine. If I replace \linebreak with \\ inside cfoot then I get an error:

ABD: EveryShipout initializing macros ! Misplaced \cr. \reserved@c ->\ifnum 0={}\fi \cr

However, if I remove about 10 rows from the table, then the table will fit a single page. And then \\ will be working in the cfoot too. No error message.

I'm not sure about this, but should't longtabu and cfoot be somewhat independent of each other? I would expect that if a cfoot content works on a page that contains regular text, then the same cfoot should work with any other content. Is this a bug? If this is not a bug then this must be a side effect of something that is hard to understand for a beginner.

• not sure about the details, but in general, it's chancy to use a double backslash for anything but the primary intended purpose -- in this case to end a row -- in an environment where it's a "core component". so \linebreak is definitely to be preferred if it's available for use. as you say, "hard to understand for a beginner" (and maybe also for some non-beginners; one learns to take it on faith.) – barbara beeton Sep 16 '14 at 20:42
• If that is the case, then I strongly recommend to change some popular books about Latex. For example, "The Not So Short Introduction to LATEX" is a very popular book. In secion 2.2 it says "\\\\ or \\newline starts a new line without starting a new paragraph". I think it would be better for beginners (like me) to use \linebreak instead. I may be wrong though, I'm really just a beginner. – nagylzs Sep 18 '14 at 12:20
• it's true that the double backslash can usually be used to break a line, but there are some situations where it conflicts with other "hidden" linebreaking mechanisms, resulting in (often mysterious) errors. usually, these situations aren't encountered by someone learning to use latex with straightforward text, so i can understand the introduction to linebreaking in documentation like "the not so short introduction" -- adding all the details there would intimidate a beginner. but maybe a footnote ... – barbara beeton Sep 18 '14 at 13:12

It's a bug in longtabu.

\newline and \linebreak have (more or less) constant definitions throughout LaTeX, but \\ has different definitions depending on context. \\ in an array is completely different to \\ in center and both are different to \\ in normal text. what happens here is that in the heading you are in the scope of \centering but \\ has its longtabu end of row definition rather than the "end line and centre" definition it should have at that point.

tabu does:

%% No need for \arraybackslash ! ------------------------------------
\def\tabu@latextwoe {%
\def\tabu@temp##1##2##3{{\toks@\expandafter{##2##3}\xdef##1{\the\toks@}}}
\tabu@temp \tabu@centering   \centering   \arraybackslash
\tabu@temp \tabu@raggedleft  \raggedleft  \arraybackslash
\tabu@temp \tabu@raggedright \raggedright \arraybackslash


which has the effect of making \centering act like \centering\arraybackslash

\arraybackslash is a command (originally from my tabularx package) that redefines \\ to have its tabular/array meaning of ending a table row.

Due to the asynchronous nature of TeX's output routine, the page breaker will be invoked to insert the page head within the scope of the table.

This means that when fancyhdr invokes \centering to centre the middle section of its head and foot it does not get the definition that it expects and \\ is locally defined to have its longtable meaning.

Whenever an environment that allows page breaking makes local redefinitions, it should ensure that they are all locally reset within the output routine so that the definitions in the page body do not leak into the head.

In this case actually I think tabu isn't really what you want here. Using X just makes the first column data needlessly far from the rest of the table, making the table hard to read. Compare the two versions:

The original longtable code doen't redefine \centering in this way.

Unrelated but you should do

\cfoot{
\hrule
\vspace{1mm}
\footnotesize %
This is line one with some text. \\%\linebreak%\\%\linebreak % Replace \linebreak with \\ here to reproduce the error
This is line two with some more text.
}


not

\cfoot{
\hrule
\vspace{1mm}
{\footnotesize %
This is line one with some text. \\%\linebreak%\\%\linebreak % Replace \linebreak with \\ here to reproduce the error
This is line two with some more text.
}}


The extra {} in your version end the scope of \footnotesize before the paragraph finishes so the foot is set with small text on a normal baseline. Note how the lines in the foot close up once the braces are removed.

\documentclass[a5paper,10pt]{article}
\usepackage{array,tabularx,longtable,tabu}
\usepackage{colortbl,tikz}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\makeatletter
\cfoot{
\hrule
\vspace{1mm}
\footnotesize %
This is line one with some text.\\
This is line two with some more text.
}

\begin{document}

\begingroup
\footnotesize
\begin{longtable}{lrlrr}
Name %
& \multicolumn{2}{c}{\bfseries Qty}
& \bfseries Price  %
& \bfseries NET
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
E2014-SPAMA-GLOB   & -1.0  & db  & 31\,833  & -31\,833  \\
\end{longtable}

\endgroup
\end{document}
`