I want to control table, created by longtable
enwironment such way that it would have pagebreak before last two lines if the rest of the table would be longer than some height (it depends on height of text, that follows the table and should be fully on last page with at least two last columns of table). The last line and text after table is static block, I put it into lastfoot
. But line before last should be always on the same page with last line.
Here is the shortest working example:
\documentclass[12pt]{letter}
\usepackage[english]{babel}
\usepackage{longtable}
\usepackage{array}
\makeatletter
\newtoks\f@st
\f@st={}
\def\pr@line#1{#1\global\f@st={}}
\def\RPOline#1#2{\pr@line{\the\f@st}\global\f@st={#1\cr\hline}}
\newcolumntype{C}[1]{>{\centering}m{#1}}
\newsavebox\l@stb@x
\def\RPOb@g{
\global\savebox{\l@stb@x}{\hbox to\textwidth{\vbox to 10cm{some text\vfill bottom}}}
\begin{longtable}{|C{1cm}|C{5cm}|}
\hline N& Name\cr\hline\endfirsthead
\endhead\endfoot
\multicolumn{2}{l}{\usebox{\l@stb@x}}\endlastfoot
}
\newtoks\old@utput
\newdimen\texth@
\old@utput=\expandafter{\the\output}
\def\ts@{\texth@=\textheight\advance\texth@ by -\ht\l@stb@x\advance\texth@ by -5mm\relax
\setbox0=\vbox{\unvbox255}\ifdim\ht0<\texth@
\setbox255=\vbox{\unvbox0\pr@line{\the\f@st}}\else
\setbox255=\vbox{\unvbox0}\fi
\the\old@utput
\global\output=\expandafter{\the\old@utput}}
\def\PRO@nd{
\global\output={\ts@}\cr\pagebreak
\pr@line{\the\f@st}
\end{longtable}
}
\newenvironment{RPOtable}{\RPOb@g}{\PRO@nd}
\makeatother
\newcount\tstcnt
\def\fillt#1{\ifnum\tstcnt>0\global\advance\tstcnt by -1\relax #1\fillt{#1}\fi}
\def\filltbl#1#2{\global\tstcnt=#1\relax\fillt{#2}}
\begin{document}
\begin{RPOtable}
\filltbl{31}{\RPOline{a}{Sample line}}
\RPOline{L}{Last line}
\end{RPOtable}
\end{document}
When I put \cr\pagebreak
into \PRO@nd
(like written above) I get no errors but have empty lines in table and the table always breaks on \pagebreak
. If I omit \pagebreak
, line marked as "Last line" stays on previous page, and there's still an empty table line after it.
Question
How can I make "unbreaking" of page with longtable
? I can't do \vsplit
bacause it is already a box. Also I always have error messages Misplased \noalign
if I don't put \cr
before of \pagebreak
.
\cr
is not a latex command but as longtable only breaks between rows, you are only allowed to use\pagebreak
immediately after\\
.\ifx\relax#1
but it appears that#1
is always\the
so the test is always false. It is very hard to guess what this is indented to do.longtable
don't work with \\, but work with\cr
(that's because of specific column types - for central alignment: I have errorsmisplaced noalign
with \). As for\ifx
I agree: this is my error, it do nothing.\\
isn't working then there is an error in the document but it's impossible to comment on the code in the form presented here, sorry, you need to post a proper example document with a description of what the intended result is, otherwise I suspect not much can be done other than close the question as "unclear"