3

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

\tracingonline=1
\advance\vsize by -15cm
\def\tablerule{\noalign{\hrule height .3mm\filbreak}}
\newcount\posno\posno=1
\def\pos{\hskip3pt\number\posno\global\advance\posno by 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.

example

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

1 Answer 1

6

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.

enter image description here

2
  • brilliant idea, I wonder if latex has a package that does that? Feb 18, 2020 at 19:51
  • @DavidCarlisle colortbl, of course :-) Feb 18, 2020 at 20:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .