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.

This is the shape a document server wants. Build the table, say what room it gets on the first page and what room on the ones after, and ask it once to break itself into pages. It answers by saying, for each page, what to draw and where. You make each page — here by laying it on an imported template — and draw what it said.

There is no loop to write and so no way to write it wrong: a table that could not advance raises an error rather than adding another blank page. The heading is drawn again at the top of every page, the footnote under the last line of every page, and a section title is kept with the rows it introduces rather than stranded at the foot of a page.

What this example shows

  • One call, answering with what to draw on each of the pages needed.
  • Heading and footnote rows repeated on every page.
  • Section titles kept with the rows underneath them.

The code, in full

The same document is written twice, once in each language. Both files are shown in full, with the code coloured on the server, and can be copied in one click.

The document itself

The same document is written in each of these languages. Open the one you want to look at.

Open the document in English Open the document in French

Read the Rust source Read the Python source

First page of A self-paginating table

What this document weighs

Before 223,298 bytes
Now 82,269 bytes
Saved 63.2 %

Not one mark on the page changed. See every document measured.

Examples near this one

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.

Pictures inside table cells

A catalogue whose first column is a picture rather than text: four pictures of very different sizes and proportions, each fitted whole and undistorted into the cell the table gives it and standing against a different corner of it, claiming no width from its column and no height from its row.

Every example, by subject