TeX Live 2014 on Xubuntu 14.04 LTS.
Minimal working example:
\documentclass[11pt, oneside]{report}
\usepackage{afterpage}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\afterpage{
\clearpage
}
\rule{1mm}{16cm}
\begin{longtable}{l}
\caption[]{\rule{2mm}{2cm}} \\
\toprule
Col 1 \\
\hline \endfirsthead
\caption[]{\textit{continued from the previous page}} \\
\toprule
Col 1 \\
\hline \endhead
\hline
\multicolumn{1}{r}{\textit{continued on the next page}} \\
\endfoot
\bottomrule
\endlastfoot
1 \\
1 \\
1 \\
1 \\
\end{longtable}
\end{document}
Trying to compile this MWE results in the following message:
! Misplaced \noalign.
\newpage ->\noalign
{\break }
l.30 \end{longtable}
The \clearpage
is necessary for the effect. Also, the first table head must not fit on the page. Reducing the first rule from 16cm
to 14cm
works.
On a side note: at 15cm
other fancy stuff is happening, but I am not concerned about that right now.
Question(s): How can I avoid this error? What causes this problem exactly?
Both questions probably supplement each other.
Update 2015-12-03: After some rest, I realized that there probably is no simple solution to this question. Both, afterpage and longtable, need to work at the end of a page. When longtable wants to start a new page, afterpage would/should want to kick in. That may not be a technical explanation, but probably hits the nail on the head as well. I assume that one would have to make afterpage longtable-aware or the other way around to make this work. In the meantime, I am using a \newpage
right before the longtable.
Before posting, I looked at these related questions and did not find an answer in there: longtable misplaced noalign, Longtable breaks afterpage, https://tex.stackexchange.com/questions/147169/misplaced-noalign-when-using-afterpage-clearpage-with-either-onehafspacing, captionof in longtable gives Misplaced \noalign, Longtable alignment with caption, ! Misplaced \omit. Longtable Error and Caption Misalign Extra alignment tab has been changed to \cr.
\newpage
before the longtable which I find cleaner in my case. There,\afterpage
contains\clearpage
before and after a\begin{landscape} ... \end{landscape}
.