Longtable appears to prevent \enlargethispage from working

The following code works for me, but if I remove the comment and thus add the longtabu/longtable, then the \enlargethispage loses its effect.

\documentclass{article}
\usepackage{lipsum}
\usepackage{afterpage}
\usepackage{longtable,tabu}
\usepackage{fancyhdr}
\usepackage[margin=2cm,showframe]{geometry}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\small\thepage}
\begin{document}
\enlargethispage{-2cm}
%\begin{longtabu}{Xl} a&b\\ \end{longtabu}
%\begin{longtable}{ll} a&b\\ \end{longtable}
\lipsum
\lipsum
\end{document}


How do I work around this?

• note that longtable uses a different page breaker (output routine) \enlargethispage is a feature of the standard one, so it's not that longtable stops it working, more a feature request that the feature be added to longtable's. – David Carlisle Sep 11 '15 at 14:54
• Are you inclined to approve of this request, because I would be happy to create one. In the end I just want to solve the question tex.stackexchange.com/questions/267067/… from earlier with longtable present. So an alternative without \enlargethispage is entirely helpful as well. – Max Sep 11 '15 at 14:57
• In your example you can simply put the \enlargethispage behind the longtable. – Ulrike Fischer Sep 11 '15 at 15:05
• @Ulrike This example is misleading in that way. The end goal is a document class. So far I use \AtBeginDocument{\enlargethispage{-2cm}}. I cannot know if longtable is part of the game or not and if it will be on the page of the header. – Max Sep 11 '15 at 15:22
• – touhami Sep 11 '15 at 16:38

Here is a solution. Newcommand \enlargemypage to be used.

Edit the command work with or without longtable.

\documentclass{article}
\usepackage{lipsum}
\usepackage{afterpage}
\usepackage{longtable}
\usepackage{fancyhdr}
\usepackage[margin=2cm,showframe]{geometry}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\small\thepage}

\makeatletter
\newcommand{\Enlargemypage}[1]{%
\global\setlength{\@colht}{\textheight}%
\global\setlength{\@colroom}{\textheight}%
\global\setlength{\vsize}{\textheight}}
\makeatother

\newcommand{\enlargemypage}[1]{%
\Enlargemypage{#1}\afterpage{\Enlargemypage{-#1}}}

\AtBeginDocument{\enlargemypage{-2cm}}

\begin{document}
\begin{longtable}{ll} a&b\\\end{longtable}
\lipsum
\lipsum
\end{document}

• I am sorry, I don't think this solves it. I don't necessarily need the page with longtable on it to be larger, but the first page in the document and it can happen or not happen that this page contains a longtable. So adding this after longtable won't help I am afraid. – Max Sep 19 '15 at 20:32
• @Max in this case just use \enlargemypage{-5cm} (updated version) after \begin{document} – touhami Sep 19 '15 at 20:44
• @Max answer edited \AtBeginDocument{\enlargemypage{-2cm}} is used. – touhami Sep 20 '15 at 15:20
• It works for the sample, but unfortunately not for my document. I guess I can make it work though. I was hoping for a real solution within longtable, but since no one else has answered yet, I will award the bounty, least it goes to waste. – Max Sep 24 '15 at 17:18
• Ok, but I can't see the problem, for me it works fine (I don't use tabu), did you see my last comment below your question? – touhami Sep 24 '15 at 17:54