9

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.

10

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}
  • 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
  • LaTeX's \@outputpage does initially call \@parboxrestore. So LaTeX's output routine already restores \\ before \@thehead. \chead uses \centering to center the element. This also redefines \\ again. The problem is, that tabu redefines \centering (and several other usual macros). And this definition is still valid while building the head or foot. So the \centering of \chead isn't LaTeX's \centering while the longtabu is active. So the problem is, that tabu does not restore the original definitions while the output is active. BTW: It's independent of the class. – Schweinebacke Apr 5 '19 at 6:27
5

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}
  • 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
1

The problem is caused by a mis-feature of tabu. In \tabu@init the package redefines several usual LaTeX commands, like \centering, \raggedright, \raggedleft (but also \fbox, \color etc.). For some of the commands this results in problems, if these are used in the page head or page footer while a longtabu is processed. Here is a MWE for this problem without using any page style package:

\documentclass{article}
\usepackage{longtable,tabu}
\usepackage{mwe}
\pagestyle{myheadings}
\begin{document}
\markright{\protect\parbox{2em}{\protect\centering One\\ Two}}
\lipsum[1-5]
\begin{longtabu}{lr}
  first & row \\
  second & row \\
  third & row \\
  fourth & row \\
  fifth & row \\
  sixth & row \\
\end{longtabu}
\end{document}

This also gives the error message from the question:

./test-longtabu.tex:15: Misplaced \cr.
\reserved@c ->\ifnum 0=`{}\fi \cr 

l.15 \end{longtabu}

A real correction of the problem can only be done by the tabu maintainer. tabu should either not redefine all those macros or should restore correctly.

However, the easiest workaround for the problem is, not to use \\ but \par:

\documentclass{scrartcl}
\usepackage{longtable,tabu}
\usepackage{lipsum}
\usepackage{scrpage2}
\chead[Headline 1\par Headline 2]{Headline 1\par 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}

But you should also switch over from deprecated scrpage2 to scrlayer-scrpage. Unfortunately, the current release of scrlayer-scrpage does not allow \par inside the argument of \chead (I've reported this already). This should be fixed in the next release of scrlayer-scrpage. Moreover scrlayer-scrpage v3.27 will provide a workaround for the tabu misfeature. So, with the current version from the subversion repository of KOMA-Script:

\documentclass{scrartcl}
\usepackage{longtable,tabu}
\usepackage{lipsum}
\usepackage{scrlayer-scrpage}
\chead*{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}

does already work.

0

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.

  • 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

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.