5

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?

Max
  • 5,702
  • 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 http://tex.stackexchange.com/questions/267067/newgeometry-and-afterpage-dont-adjust-the-geometry 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
  • see http://tex.stackexchange.com/a/267128/71471 – touhami Sep 11 '15 at 16:38
  • @touhami, your solution solves the other question, but not this one. If I understand longtable correctly then it is due to the changed output routine ignoring the \textheight. – Max Sep 12 '15 at 15:53
  • Is this about longtable or longtabu? The question says one. The code says another. (I don't know if it makes a difference to the problem, but I avoid longtabu on principle, so it makes a difference to me.) – cfr Sep 17 '15 at 02:34
  • The \enlargethispage command in latex sets the insert \@kludgeins which is in turn honoured by the \output routine. The longtable package redefines said output routine and replaces it with its own, that doesn't know about the \@kludgeins and thus in effect breaks the command. I have a rough idea where to patch it in, but have so far not been successfull. I found the problem with longtabu, but the root cause is in longtable which is what provides the page breaking behaviour to longtabu. I changed the sample to reflect this. – Max Sep 17 '15 at 08:30
  • you can see http://tex.stackexchange.com/questions/213750/customizing-the-height-of-the-pages/265893#265893 – touhami Sep 20 '15 at 15:23
  • another way is \usepackage[margin=2cm,bottom=4cm,showframe]{geometry} this set text height -2cm and \makeatletter \AtBeginDocument{% \afterpage{% \global\addtolength\textheight{2cm}% \global\setlength{\@colht}{\textheight}% }} \makeatother will add 2cm. – touhami Sep 23 '15 at 07:50

1 Answers1

1

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\addtolength\textheight{#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}
touhami
  • 19,520
  • 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