Tables

A Markdown table is two different things wearing one syntax. Most tables in a manual are reference lists: a short key, then a sentence or two about it. A few are true grids, read across and down. Press reads the shape from your cells and sets each table by what it is, in every edition.

Write a pipe table

Write tables the ordinary way, as pandoc pipe tables. A caption goes on a line of its own after the table, starting with :.

| Command        | What it does                                              |
| -------------- | --------------------------------------------------------- |
| `press all`    | Builds every edition, then runs every verifier against it. |
| `press check`  | Lints the manuscript without building anything.            |
| `press doctor` | Reports which tools the build can find on this machine.    |

: The three commands you run most

You do not choose a layout, set column widths, or mark the table up. The press reads the cells and decides. If it decides wrong, one fenced div overrides it (see “Force a shape” below).

Two shapes

The reason for the rule is a count. The first manual built with press, Publishing with Press, has 116 tables; 106 of them are a key column plus exactly one column of prose. Set as a grid, that prose column is squeezed into a third or half of the measure and wraps a word or two to a line, and on a phone it is worse. So press renders the two shapes differently.

A reference list becomes a ledger. A table is a reference list when it has two or three columns, exactly one of them is prose (its cells average eight words or more), and that prose column is the last one. A code span counts as one word however long it is, so a key like press all is as short as pandoc. A ledger is the manpage form:

A ledger has no column to squeeze, so it reads the same in a 6 by 9 print measure, at 390 pixels on a phone, in an EPUB reader, and in Word.

Everything else is a grid. One column, four or more columns, no prose column, two prose columns, or a prose column that is not last: those are grids, read across rows, and they stay tables. A grid gets fixes that make it honest:

Force a shape

The rule reads cells, not intent. When it guesses wrong, wrap the table in a fenced div with the class you want:

::: {.grid}
| Flag      | Meaning                                                        |
| --------- | -------------------------------------------------------------- |
| `--watch` | Rebuilds the edition whenever a manuscript file changes on disk. |
:::

::: {.ledger} forces a ledger the same way. Every table inside the div takes the forced shape. When the div holds just the one table, it becomes the table’s wrapper itself: the rendered page carries one div.grid or div.ledger, not one nested in another, and the div’s id and any other classes and attributes you gave it are kept, so {#flags .grid .wide} still has its anchor and its extra class.

A one-column table is always a grid: a ledger needs a key and something to say about it, so ::: {.ledger} around a one-column table still renders a grid. So does a table that is all header row: with no body rows there is no entry to list.

What each edition renders

Edition Ledger Grid
PDF and print A hanging description list: the key on its own line, the entry indented 1.6 em, a check before each key so it never strands at a page foot; the caption and the small-capitals legend above, kept on the page with the first entry. A smaller table with relative column widths that wrap, 0.5 em cell padding, room asked for before the head, and code that never hyphenates.
Reader site and HTML A definition list in .ledger: the key in semibold, a hairline between entries, the middle column (.ledger-sub) in constant width. The table in .grid at reading width, scrolling inside its own box if it is wider than the page. On a phone each row stacks into a card, each cell labelled with its column’s header, and code wraps inside the card.
EPUB The same .ledger list, plain: no colour and no web fonts, because the reader’s device owns the theme. The table in .grid, with the same widths.
DOCX A native Word definition list, in pandoc’s DefinitionTerm and Definition paragraph styles. The caption and legend arrive as ordinary body paragraphs, unstyled, until the house ledger styles land with the generated reference document. The table, with the same relative column widths, which Word honours.
Markdown and plain text The Markdown edition is your stitched source and keeps the pipe table; plain text prints an indented list. The Markdown edition keeps the pipe table. Plain text prints the grid as a full-width table with ruled top and bottom, its columns in the same proportions as the other editions.

A book with no tables renders as it did before, apart from the new rules in the stylesheets the editions carry: the shapes are added only where a table is.

What the verifiers refuse

A producer is only proven by a check that rejects a broken result, so two verifiers run on every press all. Both are listed in the invariants.

Measuring a built site

The verifiers prove every table is in a shape; they do not say how well the shapes read. For that, maintainers have scripts/measure_tables.py, a heuristic instrument rather than a gate. Point it at a built reader site:

python3 scripts/measure_tables.py BOOK/dist/pages/read

It loads every page in headless Chrome at 1280, 820, and 390 CSS pixels (--widths changes them) and reports, per width: code spans in a table or a ledger split inside a token (an identifier broken mid-word), code wrapped at a space, sparse cells (three or more lines averaging under 1.5 words a line), cells five or more lines tall, tables wider than the measure, clipped cells, and pages that scroll sideways. It also counts the .ledger and .grid elements on each page and in total. Lines are counted from the cell’s boxes bucketed by line height, so treat the numbers as a comparison between two builds of the same book. --json prints the raw results, and --fail-on-any exits 1 when any width has an in-token split, a clipped cell, or a page scrolling sideways. With no Chrome installed it prints a notice and exits 0; PRESS_CHROME points it at a browser.