# Additional hrule in halign after page break

I try to spread a halign over more than one page. I use \filbreak after every line.

\tracingonline=1
\def\tablerule{\noalign{\hrule height .3mm\filbreak}}
\newcount\posno\posno=1
\tabskip=0pt%
\halign to 400pt{\vrule width 0pt height 12pt depth 6pt#\tabskip=1em&#\tabskip=1em&#\tabskip=1em plus 1fil&#\tabskip=1em\cr
\tablerule%
\hskip3pt%
{\bf Pos.} & {\bf Anz.} & {\bf Beschreibung} & {\bf Seriennummer}\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
\pos & 1 St. & Abcdefg & 123/12/12-1234567\cr\tablerule
}
\bye


The problem is: when a page break happens an \hrule is missing at the top of the new page.

Is is possible to check if \filbreak has created a page break in order to add an additional \hrule for the new page?

You can't detect that because at the time TeX does page-breaking it has long finished expanding macros. However you can trick it into inserting a rule there for you.

If you change your \tablerule to:

\def\tablerule{\noalign{%
\hrule height .3mm
\filbreak\vskip-.3mm
\hrule height .3mm}}


then each rule will be doubled, but due to the negative \vskip they will overlap, so only one will be visible. However at a page break the rules will be separated across pages due to the \filbreak, and the \vskip will be discarded at the top of the next page, and you will have the two rules you want.

This is (an oversimplified version of) what longtable does when it finds an \hline, except that longtable generalises for the case of different rule widths and a possible double \hline.

• brilliant idea, I wonder if latex has a package that does that? – David Carlisle Feb 18 '20 at 19:51
• @DavidCarlisle colortbl, of course :-) – Phelype Oleinik Feb 18 '20 at 20:22