Two orders, one frame, one bottom edge

A pad of printed stationery has the frame on the paper already: a box for the lines, a rule under it, the total below the rule. What goes in the box is a different length every time. An order of four lines leaves a hand's breadth of white above the rule and an order of a dozen fills it, so two sheets from the same pad look like two different documents — and the usual answer, padding the short one with empty rows, is a row somebody can write in afterwards.

Here the box is filled instead. Whatever room the lines leave is shared out among them in equal parts, once they have all been measured, so the last line lands on the bottom edge whichever order is being printed. The headings and the total stay exactly where the paper puts them. The two notes at the foot of the page do the same with words rather than rows: their lines are moved apart until each note reaches the bottom of its box, so notes of unequal length end on one line — and a limit is given along with the box, so a note of two lines keeps the spacing it came with.

What this example shows

  • The bottom edge is the same whether the order runs to four lines or fifteen.
  • The headings and the total stay where the printed paper puts them.
  • Two notes of unequal length brought to one common last line.

The code that writes it, in full

Whole programs, hundreds of lines long, for whoever writes your software.

Read the Rust source Read the Python source

The document itself

Open the document in English Open the document in French

Examples near this one

A multi-page invoice table

Twelve lines is one page and thirty is two — and the second has to look exactly like the first, or the invoice comes back from the customer's accounts department.

A self-paginating table

A long table handed over whole, deciding for itself where the pages break: its heading on top of every page, its footnote under every page, its grey grounds stated once for the whole table, and a note you draw under each page at the exact place the table reports.

Cells merged down the rows

A specification sheet whose cells are merged down the rows: each group named once beside all of its rows, with one note beside them; the thin lines stop at those cells' edges, and a note too long for the rows it covers makes them grow.

Columns measured from their cells

One parts list twice: four columns sharing the width equally, then the reference, the quantity and the price each as wide as their own widest cell and the description given everything they leave.

Every example, by subject