Skip to main content
Recipe number 37

Cookbook · Chapter 9 · Complete publications

Annual report with flush columns

An energy co-op's annual report in two justified columns that end on the same grid line, with a key-figures box across the page and a closing page cut level.

  • Trim 210 × 280 mm
  • 2 columns, 7 mm gutter
  • Brygada 1918 9.4/13.4
  • Epilogue
  • Spline Sans Mono
  • 5 pages
  • Level
  • Postext 1.65.0
  • Laid out in 169 ms
  • 250 lines of code

In short

The yearly report of a small community energy group, set in two columns. It shows how to make both columns of text end at exactly the same height.

What you'll build

The 2025 annual report of Tidewell Community Energy, an invented co-operative with two wind turbines, a solar field and panels on 21 roofs. Five pages at 210 × 280 mm. On the cover, the year's wind and sun output runs as two ribbons under a 150 pt “2025”. The chair's letter, the operations report and the treasurer's accounts follow in two justified columns of Brygada 1918 on a grid of 50 lines. Full columns end on the grid's last line, and short ones end level with their neighbours. A box of three key figures crosses the chair's page with the letter cut level above it, and a note on metering floats to the head of page 4. On the closing page both columns stop on one line above the income statement. A palette attribute turns the operations pages teal and the finance page brick red.

This recipe answers

  • How do I get flush column bottoms and a balanced last page (vertical justification)?
  • How do I set a box across both columns mid-page, such as a 3-up "in numbers" panel?
  • How do I float a box to the top or bottom of the page while the text keeps flowing?
  • How do I make a table with header rows, merged cells, column widths and per-cell alignment?
  • How do I divide a book into parts or sections, each with its own colour and divider page?

The short answer

script.js · lines 41–58in full code
// The text block is LINES lines of LEAD deep (MARGIN.bottom is derived from them) and every
// heading takes whole lines, so a column the break rules leave short is short by whole lines.
// Balancing (on by default) stretches it back to its foot with its levers, in this order: a
// box that closes the column moves down to it; a picture with a safe area grows; lines above
// the headings, two each at most (maxLinesBeforeLoose); one line where a list ends; one under
// a display formula or a box, then under a float at the column head; a paragraph set one line
// longer and looser, with up to maxTracking of tracking; last, the lines a heading may still
// take, up to maxLinesPerHeading. A closing band whose columns differ by more than a line is
// cut level instead (trailing), and so is the band a page-wide box leaves when it has to move
// on to the next page (beforeSpan).
const balancing = { maxLinesPerHeading: 1 }; // one line per heading; the next lever takes more
const flowText = { // justification, hyphenation and Knuth–Plass stay at their defaults (on)
  fontFamily: 'Brygada 1918', fontSize: pt(9.4), lineHeight: pt(LEAD),
  firstLineIndent: mm(4), indentAfterHeading: false,
  minWordSpacing: 0.7, maxWordSpacing: 1.8, // word spaces 0.7–1.8 of normal (defaults 0.6–2)
};
const onGrid = { lineHeight: pt(LEAD), marginTop: pt(LEAD), marginBottom: pt(0) }; // one line
// hook-up: headings: { balancing, levels: [..., { level: 2, ...onGrid }] }, bodyText: flowText

Flush columns: whole grid lines everywhere, and the balancing levers

Ingredients

Type
Brygada 1918, Epilogue, Spline Sans Mono, Mrs Saint Delafield (SIL OFL 1.1)
Assets
None: every picture is drawn in code

Method

#1 · Keep every line on the grid and let the levers close the gaps

The code is the short answer above. The text block is exactly 50 lines of 13.4 pt deep, and the bottom margin (21.6 mm) is derived from that depth. A crosshead takes one grid line above it and one for itself, so a column that ends short is short by whole lines, and whole lines are what column balancing adds. On page 3 the three-line hailstorm paragraph goes whole to page 4 under avoidOrphans, Postext's name for the rule that keeps a paragraph's last line from standing alone at the head of a column, and the right column ends two lines short. maxLinesPerHeading: 1 gives one of those lines to the space above The Saltings and the roofs and leaves the other to the next lever, which adds it after the list of roofs. By default a heading takes up to two lines before the levers after it are tried (maxLinesBeforeLoose), and up to four once they have nothing left to give, so both lines would go above the heading.

#2 · Cut the text level above a box that crosses the page

script.js · lines 101–109in full code
// In the Markdown: :::callout{type="figures" span="page"} around :::columns{count=3 breaks="3,5"},
// each number a :::paragraphs{style="figure"} of **8.47 GWh**, then its line of text.
const figures = { id: 'figures', background: col('ink'), columnGap: mm(GUTTER),
  padding: { top: mm(5), right: mm(5), bottom: mm(5), left: mm(5) },
  marginTop: pt(LEAD), marginBottom: pt(LEAD), titleStyle: { ...boxTitle, color: col('sun') },
  body: { fontFamily: 'Epilogue', fontSize: pt(9), lineHeight: pt(12), color: col('paper'),
    ...boxText } };
const bigNumber = { id: 'figure', fontFamily: 'Epilogue', fontSize: pt(26), lineHeight: pt(31),
  color: col('paper'), boldColor: col('sun'), ...boxText };

A box with span="page" cuts a two-column page into bands. On page 2 the chair's letter stops at eight lines in each column above the box and carries on in both columns under it. Inside the box, :::columns{count=3 breaks="3,5"} opens the second and third columns at the second and third numbers (the group's third and fifth blocks) instead of cutting the run where the columns level best. The figure paragraph style sets those numbers at 26 pt, and its boldColor prints them in yellow.

#3 · Float a box to the head of the next page

script.js · lines 113–122in full code
// In the Markdown: :::callout{type="aside" span="page" placement="top"}. It leaves the flow
// where it stands and takes the head of the next page the flow opens; the text goes on
// filling this one. It has a stripe in the section's colour and no fill. The padding under
// the text drops the floats below the box by a grid line, so they stand clear of it.
const aside = { id: 'aside', backgroundEnabled: false, columnGap: mm(GUTTER),
  stripe: { enabled: true, side: 'top', width: pt(2.5), color: col('band') },
  padding: { top: mm(3.5), right: pt(0), bottom: mm(3.5), left: pt(0) },
  titleStyle: { ...boxTitle, color: col('band') },
  body: { fontFamily: 'Epilogue', fontSize: pt(8.6), lineHeight: pt(12.2), color: col('ink'),
    ...boxText } };

In the Markdown the note on metering follows the first paragraph about Harrow Down, on page 3; placement="top" takes it out of the flow and sets it at the head of the next page. The report fills the rest of page 3, and page 4 opens with the box across both columns. Under it, the site table and the ring chart, both position: 'top', head one column each, a grid line lower than they would sit without the box's 3.5 mm of bottom padding.

#4 · Give each section its colour without a divider page

script.js · lines 14–27in full code
const palette = {
  ink: '#14202b', // text: a blue-black
  band: '#0b5d7a', // sea, overridden by palette="band=#…" on the :::part fences
  wind: '#3aa6a0', sun: '#f2b134', coral: '#e2674b', // the data colours of the charts
  tint: '#eef3f5', // subtotal rows
  rule: '#c9d3d9', // hairlines
  muted: '#566370', // captions' notes and the running feet
  mist: '#9fb1bd', // small print on the ink cover
  paper: '#ffffff',
};
// Every colour is linked to its palette entry, so a :::part recolours it by paletteId.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries(palette)
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));

With parts: { page: false } a fence such as :::part{number="02" title="Operations" palette="band=#1c6e67"} opens no page. It names the section for the opener strip and the running feet, and swaps band on every page until the next part. The strips, crossheads, bullets, caption labels and the aside's rule all take band, so the operations pages print in teal and the finance page in brick red, while the chair's letter keeps the base sea blue (colours per part).

#5 · Build the tables from the data, and close the last page level

script.js · lines 170–219in full code
const DATA = {
  // Output in MWh at the export meter, January to December 2025.
  wind: [560, 520, 450, 330, 270, 210, 190, 150, 300, 420, 480, 540], // Harrow Down
  sun: [90, 160, 300, 440, 560, 600, 580, 500, 380, 250, 120, 70], // the Saltings + 21 roofs
  // The turbines' year, % of the hours of both machines: [label, share, palette colour].
  hours: [['generating', 78.0, 'wind'], ['waiting for wind', 16.8, 'rule'], ['bearing repair', 2.6,
    'coral'], ['servicing and grid', 1.8, 'sun'], ['stopped for bats', 0.8, 'ink']],
  // Output by site in MWh: [site, source, capacity in MW, 2025, 2024].
  sites: [['Harrow Down', 'wind', 1.8, 4420, 4560], ['The Saltings', 'solar', 3.2, 3190, 2640],
    ['21 roofs', 'solar', 0.9, 860, 790]],
  // £ thousand, [label, 2025, 2024]; a label alone opens a group, '=' prints the running sum.
  accounts: [['Income'], ['Electricity sold under the power purchase agreement', 760, 722],
    ['Electricity sold to roof hosts', 92, 85], ['Feed-in tariff', 236, 229], ['=Total income'],
    ['Operating costs'], ['Operation and maintenance', -231, -198],
    ['Rent, rates and insurance', -158, -151], ['Staff and administration', -121, -112],
    ['Depreciation', -286, -286], ['=Operating surplus'],
    ['Interest on the Harrow Down loan', -54, -66], ['Interest on members’ shares at 3.5%', -113,
      -107], ['Grants to the Tidewell Fund', -84, -70], ['Corporation tax', -5, -7],
    ['=Surplus for the year']],
};
const fill = { background: col('tint') }; // totals sit on a tint between two hairlines
const right = (content, extra) => ({ content, align: 'right', ...extra });
const figure = (n, digits = 0) => n.toLocaleString('en-GB', { minimumFractionDigits: digits });
const head = (c, i) => (i ? right(c, { isHeader: true }) : { content: c, isHeader: true });
const siteTable = (rows) => ({ headerRowCount: 1, columnWidths: [3, 1, 1.3, 1.3], rows: [
  ['Site', 'MW', '2025', '2024'].map(head),
  ...rows.map(([site, source, mw, ...n]) => [{ content: `${site} *(${source})*` },
    right(figure(mw, 1)), ...n.map((v) => right(figure(v)))]),
  [{ content: '**All sites**', ...fill }, ...[2, 3, 4].map((i, k) => right(`**${figure(rows
    .reduce((sum, row) => sum + row[i], 0), k ? 0 : 1)}**`, fill))]] }); // the totals, summed
// Accounting style: losses in brackets, and gains followed by a no-break space, as wide as a
// bracket in a monospaced face, so the digits line up.
const pad = '\u00a0';
const money = (n) => (n < 0 ? `(${figure(-n)})` : `${figure(n)}${pad}`);
function statement(rows) {
  const sum = [0, 0];
  const cells = [['£ thousand', `2025${pad}`, `2024${pad}`].map(head)];
  for (const [label, ...years] of rows) {
    years.forEach((n, i) => { sum[i] += n; });
    const sub = label.startsWith('='); // a subtotal: the running sum, in bold
    cells.push(sub ? [{ content: `**${label.slice(1)}**`, ...fill },
      ...sum.map((n) => right(`**${money(n)}**`, fill))]
      : [{ content: years.length ? label : `*${label}*` }, // a label alone heads a group
        ...[0, 1].map((i) => right(years.length ? money(years[i]) : ''))]);
  }
  // mergeCells writes the cells a spanning group head hides (gotcha: merged-cells-hiddenby)
  return cells.reduce((model, row, r) => (r && !row[1].content ? mergeCells(model,
    { start: { row: r, col: 0 }, end: { row: r, col: 2 } }) : model),
  { rows: cells, headerRowCount: 1, columnWidths: [5, 1, 1] });
}

statement() turns DATA.accounts into the income statement row by row. A label that starts with = prints the running sum of each year in bold on the tint; costs are negative in the data, so Operating surplus comes out of that sum with no total typed by hand. A label with no figures, Income or Operating costs, becomes one italic cell across the table, merged with mergeCells, which also writes the placeholder cells a merge needs. On page 5 the statement floats across the foot of the page, under the treasurer's report, which closes the document. Unbalanced, the columns would run to 12 lines on the left and 9 on the right; the trailing cut sets both at 11, and the heading lever adds the line the right column still lacks above Cash and reserves.

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 037 · Annual report with flush columns ═══════════════════════
// https://postext.dev/en/cookbook/annual-report-flush-columns
// Code: MIT · Text: original (CC BY 4.0) · Art: drawn in code · Typefaces: SIL OFL 1.1
// Fonts: Brygada 1918, Epilogue, Spline Sans Mono, Mrs Saint Delafield · Needs postext ≥ 1.28.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, mergeCells, inlineSvgFonts,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'annual-report-flush-columns';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: 'band' is the first section's colour; each later :::part brings its own
const palette = {
  ink: '#14202b', // text: a blue-black
  band: '#0b5d7a', // sea, overridden by palette="band=#…" on the :::part fences
  wind: '#3aa6a0', sun: '#f2b134', coral: '#e2674b', // the data colours of the charts
  tint: '#eef3f5', // subtotal rows
  rule: '#c9d3d9', // hairlines
  muted: '#566370', // captions' notes and the running feet
  mist: '#9fb1bd', // small print on the ink cover
  paper: '#ffffff',
};
// Every colour is linked to its palette entry, so a :::part recolours it by paletteId.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries(palette)
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const TRIM = { width: 210, height: 280 };
const LEAD = 13.4; // body leading in pt: one line of the baseline grid
const LINES = 50; // grid lines in a full column
const MARGIN = { top: 22, inner: 18, outer: 16 }; // mm, mirrored
MARGIN.bottom = TRIM.height - MARGIN.top - (LINES * LEAD * 25.4) / 72; // 21.6 mm: 50 lines exactly
const GUTTER = 7; // mm between the columns, and between the columns inside the boxes
const mono = { fontFamily: 'Spline Sans Mono', fontWeight: 500, textTransform: 'uppercase' };
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const text = (id, content, look, placement) => ({ kind: 'text', id, content, placement,
  align: 'left', ...look });

// #region answer: flush columns: whole grid lines everywhere, and the balancing levers
// The text block is LINES lines of LEAD deep (MARGIN.bottom is derived from them) and every
// heading takes whole lines, so a column the break rules leave short is short by whole lines.
// Balancing (on by default) stretches it back to its foot with its levers, in this order: a
// box that closes the column moves down to it; a picture with a safe area grows; lines above
// the headings, two each at most (maxLinesBeforeLoose); one line where a list ends; one under
// a display formula or a box, then under a float at the column head; a paragraph set one line
// longer and looser, with up to maxTracking of tracking; last, the lines a heading may still
// take, up to maxLinesPerHeading. A closing band whose columns differ by more than a line is

The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)

Variations

#Let the headings take the whole gap

Both free lines on page 3 then go above The Saltings and the roofs, and none after the list.

-const balancing = { maxLinesPerHeading: 1 }; // one line per heading; the next lever takes more
+const balancing = {}; // the default: two lines above a heading, then the other levers

#Switch the balancing off

The right column of page 3 then ends two lines short. On page 5 the left column runs to 12 lines and the right to 9, and the statement starts a line lower.

-const balancing = { maxLinesPerHeading: 1 }; // one line per heading; the next lever takes more
+const balancing = { enabled: false };

Pitfalls

Pitfall

avoidWidows guards the foot of a column, avoidOrphans its head

Postext names the two lone lines its own way: avoidWidows (widowMinLines, widowPenalty) keeps a paragraph's first line from standing alone at the foot of a column, and avoidOrphans (orphanMinLines, orphanPenalty) keeps its last line from standing alone at the head of the next. Many style manuals give the two names the other way round, so pick the setting by where it acts. Both are on by default, except on a character grid (cjk.grid): there avoidWidows is off, and avoidOrphans too in the Japan region, so that a page holds the lines its grid counts (since postext 1.28). They work as penalties: the layout weighs each one against the empty lines that obeying it would leave. Widows, orphans and runts →

Pitfall

Merged cells need hiddenBy placeholders: use mergeCells

Cells are laid out by their position in the row array, so a merged cell needs placeholder cells marked hiddenBy where it spreads; leaving them out, as HTML does, shifts every later column. Build merges with mergeCells. Since postext 1.5 a table whose grid is irregular is reported in doc.contentWarnings as raggedTableGrid, and parseTSV(text, { headerRows }) marks the head rows. Tables from data →

  • When the columns of a closing page differ by one line they stay as they are, the left column a line longer, as a compositor would set them; the trailing cut acts only on a difference of two lines or more. To end the two together, lengthen or shorten the copy by a line.
  • The income statement sets costs in brackets. To line up positive figures with them, the pen ends each positive figure with a no-break space, which in a monospaced face is as wide as the closing bracket; a table cell keeps that space at the end of its text.

Credits

Text
Original prose, CC BY 4.0
Fonts
Brygada 1918 (SIL OFL 1.1) · Epilogue (SIL OFL 1.1) · Spline Sans Mono (SIL OFL 1.1) · Mrs Saint Delafield (SIL OFL 1.1)
Sandbox