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.

Please consider the following MWE:

\documentclass{scrartcl}
\usepackage{longtable,tabu}
\usepackage{lipsum}
\usepackage{scrpage2}
\chead[Headline 1\\ Headline 2]{Headline 1\\ Headline 2}
\pagestyle{scrheadings}

\begin{document}
\lipsum[1-5]
\begin{longtabu}{XXX}
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
\end{longtabu}
\end{document}

I noticed that the compilation of this MWE causes the following error:

! Misplaced \cr.
\reserved@c ->\ifnum 0=`{}\fi \cr 

l.17 \end{longtabu}

I can't figure out why you would want to use a tab mark
or \cr or \span just now. If something like a right brace
up above has ended a previous alignment prematurely,
you're probably due for more error messages, and you
might try typing `S' now just to see what is salvageable.

For one document, I needed a two-line page header and got this error, which — I guess — belongs to the tabu package. I can't find any error in it and would be delighted about help how I can get a line break in the page header without this error.

share|improve this question

3 Answers 3

up vote 8 down vote accepted

the page head is catching longtables version of \\ easiest is just to avoid the problem by using the alternative form

\chead[Headline 1\linebreak Headline 2]{Headline 1\linebreak Headline 2}
share|improve this answer
    
Thank you really much for your fast answer, which solved the issue for me. –  DigNative Mar 27 '12 at 12:27
    
arguably it is a bug in the class as if it redefines the headline so multiple lines work, it should locally run LaTeX's \@parboxrestore command to ensure that it has the correct definition of \\ –  David Carlisle Mar 27 '12 at 14:05
    
I had the same problem and your solution worked fine, but shouldn’t this be fixed in longtable or scrpage2? I didn’t understand which package has the bug, but the redefinition that longtable does should be local in {longtable}, isn’t it? –  Tobi Nov 28 '12 at 11:39
    
The definition of \\ is local to longtable but the page breaker works asynchonously and fires while longtable is active the header code if it is setting up multiline headers should execute \@parboxrestore to locally reset the environment including the definition of \\ I suppose LT could do this in its output routine wrapper but the proper place really is in the header code, the standard LaTeX headers are in a one line hbox so it is not an issue there. –  David Carlisle Nov 28 '12 at 13:01

longtabu redefines (like every tabular) \\ and in the header this definition is still active and leads to chaos. Use another command:

\documentclass{scrartcl}
\usepackage{longtable,tabu}
\usepackage{lipsum}
\usepackage{scrpage2}
\let\ORInewline\\
\chead[Headline 1\ORInewline Headline 2]{Headline 1\ORInewline Headline 2}
\pagestyle{scrheadings}

\begin{document}
\lipsum[1-5]
\begin{longtabu}{XXX}
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
    Col1 & Col2 & Col3 \\
\end{longtabu}
\end{document}
share|improve this answer
    
Thank you for your fast answer. Despite your solution solves the issue for me, I think the solution of David Carlisle is the more "clean" one, since I don't need to introduce a new command. Nevertheless, thank you really much for your efforts. –  DigNative Mar 27 '12 at 12:29
    
Yes, I hadn't checked if there already exists a suitable alias. But I will let the answer stay as it can be used as a template in case other commands in the header conflict with longtabu. –  Ulrike Fischer Mar 27 '12 at 12:42

I have had the same problem and the way to solve it is the replace all the \\ in the headers/footers definitions with \newline.

Also note that the same problem will happen with fancyhdr.

share|improve this answer
    
actually \newline doesn't trigger the lines to be centered in the same way, you need \linebreak to get the same effect as you'd get with \\ without the table. –  David Carlisle Mar 27 '12 at 12:18
    
Thanks for the correction. I used \newline in my case and it solved my problem but I wasn't using the centered header or footer but only the left and right ones, and it didn't appear to be a problem in these cases. –  ArTourter Mar 27 '12 at 15:19

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.