2

I am generating a PDF automatically from a database and I want to fill the last page up with empty rows. The document looks like

\documentclass{article}
\usepackage{longtable}
\usepackage{tabu}

\begin{document}
\begin{longtabu}{l|l|l}
normal & text & here \\
% add fillers until page is full
\hline
& & \\
\hline
& & \\
\hline
% table footer should just fit on the page
\end{longtabu}

\end{document}

The question is how to create as many empty rows between the two comments automatically without increasing the page number of the document? A decent approximation would be good enough, e.g. 5 rows instead of 6 would still be good enough for this purpose. Having to pre-create 100 rows and suppressing the overflowing ones would likely also be acceptable.

joerg
  • 31
  • If your table spans multiple pages, then you have an idea from the previous page(s) how many lines fit on each page of the table. If the lines are all about the same same height and if you know how many lines are on the last page of the table, you can estimate how many blank lines you need to include to get the table footer at the bottom of the page. Or is there something more complex at work that wasn't obvious from the example? – Susan Nov 03 '14 at 18:55
  • The programmatic glue is what I am missing, especially for the single page case. In some cases, rows will span more than one line. – joerg Nov 03 '14 at 22:35
  • please give us a more representative example of your table, so we can give you a better answer. – Susan Nov 04 '14 at 02:47

1 Answers1

2

You can use \pdfsavepos to see where the table foot landed and and generate an appropriate number of blank rows. It may take a few runs to stabilise...

enter image description here

\documentclass{article}
\usepackage{longtable}
\usepackage{tabu}


\makeatletter
\let\xwrite\write
\def\foo#1#2{\noalign{\gdef\tmp{}\xfoo{#1}{#2}\aftergroup\tmp}}

\def\xfoo#1#2{%
\ifnum#1>\z@
\expandafter\@firstofone
\else
\expandafter\@gobble
\fi
{\expandafter\gdef\expandafter\tmp\expandafter{\tmp#2}%
\xfoo{\numexpr#1-1\relax}{#2}}%
}
\makeatother
\begin{document}
%\tracingall

\ifx\zz\undefined
\def\zz{0}
\fi
\ifx\zpos\undefined
\else
% height in sp - target height of the foot
% / 2^16 to get space to fill in pt
% / 21 as roughly the height of a line+\hline + a bit for luck
\edef\zz{\the\numexpr(\zz+((\zpos-11598372)/65536)/21)\relax}
\write\csname @auxout\endcsname{\gdef\string\zz{\zz}}
\fi
\typeout{extra lines = \zz}
\begin{longtabu}{l|l|l}
THe&head&line\endhead
\pdfsavepos\write\csname @auxout\endcsname{\gdef\string\zpos{\the\pdflastypos}}
The&foot&line\endfoot
normal & text & here \\
% add fillers until page is full
\hline
\foo{\zz}{& & \\\hline}
& & \\
\hline
% table footer should just fit on the page
\end{longtabu}

\end{document}
David Carlisle
  • 757,742