本文へスキップ
レシピ番号37

レシピ集 · 第9章 · 完成した出版物

段末のそろった年次報告書

エネルギー協同組合の年次報告書。両端そろえの2段組みが同じグリッド線で終わり、ページ幅の主要数値の囲みが入り、最終ページも段末がそろいます。

1ページ(全5ページ)

  • 英語の見本:日本語版はまだありません
  • 仕上がり210 × 280 mm
  • 2段, 段間7 mm
  • Brygada 1918 9.4/13.4
  • Epilogue
  • Spline Sans Mono
  • 5ページ
  • レベル
  • Postext 1.65.0
  • 組版時間169 ms
  • コード250行

かんたんな説明

地域のエネルギー協同組合が毎年出す報告書を、2段組みで組んだ例です。左右の段の文章をぴったり同じ高さで終わらせる方法を示します。

できあがり

Tidewell Community Energyの2025年次報告書です。風車2基、太陽光発電所1か所、21棟の屋根のパネルをもつ架空の協同組合で、判型は210 × 280 mm、全5ページ。表紙では150 ptの「2025」の下に、その年の風力と太陽光の発電量が2本のリボンになって流れます。続いて理事長の手紙、事業報告、財務担当の決算報告が、Brygada 1918の両端そろえ2段組みで、50行のグリッドに組まれます。いっぱいの段はグリッドの最終行で終わり、短い段は隣の段と高さをそろえて終わります。理事長のページには3つの主要数値を収めた囲みがページ幅で入り、手紙はその上で高さをそろえて切られます。計量についての注記は4ページ目の頭にフロートします。最終ページでは、左右の段が損益計算書の上の同じ行で止まります。パレット属性によって、事業報告のページは青緑に、財務のページはれんが色になります。

このレシピが答える質問

  • 段の下端をそろえ、最終ページの段の長さを均等にするには(垂直方向の両端そろえ)?
  • ページの途中に、2段をまたぐ囲み(3つ並びの「数字で見る」欄など)を置くには?
  • 本文を流したまま、囲みをページの上端や下端にフロートとして配置するには?
  • 見出し行、結合セル、列幅、セルごとのそろえを備えた表を作るには?
  • 本を部や節に分け、それぞれに専用の色と中扉を付けるには?

手短な答え

script.js · 41〜58行コード全体で見る
// 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

材料

種類
Brygada 1918, Epilogue, Spline Sans Mono, Mrs Saint Delafield (SIL OFL 1.1)
素材
なし:画像はすべてコードで描画

作り方

#1 · すべての行をグリッドに乗せ、すき間は調整手段に埋めさせる

コードは上の手短な答えにあります。版面はちょうど13.4 ptの行が50行分の深さで、地の余白(21.6 mm)はその深さから導きます。小見出しは上に1行、自身に1行のグリッド線を使うので、段が短く終わるときの不足は行単位になり、段末そろえが足すのも行単位です。3ページ目では、3行のひょうの段落がavoidOrphansによってまるごと4ページ目へ送られます。これは段落の最終行が段の頭にひとりで立つのを防ぐ、Postextでの規則の名前です。その結果、右段は2行短く終わります。maxLinesPerHeading: 1はそのうち1行をThe Saltings and the roofsの上の空きに回し、残る1行を次の調整手段に任せます。次の手段はそれを屋根のリストの後に加えます。初期値では、見出しはまず2行まで受け取り、そのあとで後続の調整手段が試されます(maxLinesBeforeLoose)。それらに余地がなくなって初めて4行まで受け取るので、2行とも見出しの上に入ります。

#2 · ページ幅の囲みの上で本文の高さをそろえて切る

script.js · 101〜109行コード全体で見る
// 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 };

span="page"を指定した囲みは、2段組みのページを上下の帯に分けます。2ページ目では、理事長の手紙が囲みの上で左右とも8行で止まり、囲みの下で再び2段に続きます。囲みの中では、:::columns{count=3 breaks="3,5"}が2番目と3番目の段を2番目と3番目の数値(グループの3番目と5番目のブロック)から始めます。段の高さがいちばんそろう位置で切るのではありません。figure段落スタイルがこれらの数値を26 ptにし、そのboldColorが黄色で印刷します。

#3 · 囲みを次のページの頭へフロートさせる

script.js · 113〜122行コード全体で見る
// 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 } };

Markdownの中で、計量についての注記はHarrow Downについての最初の段落の後、3ページ目にあります。placement="top"はこれを流れから取り出し、次のページの頭に置きます。報告は3ページ目の残りを埋め、4ページ目は2段にまたがる囲みで始まります。その下で、拠点の表とリンググラフ(どちらもposition: 'top')がそれぞれ1段の頭に入ります。囲みの下内側余白3.5 mmがあるため、囲みがない場合より1グリッド線低い位置です。

#4 · 区切りページなしで節ごとに色を変える

script.js · 14〜27行コード全体で見る
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' } }));

parts: { page: false }のもとでは、:::part{number="02" title="Operations" palette="band=#1c6e67"}のような:::partはページを開きません。節の冒頭の帯と地側の柱に出す節の名前を決め、次の部まですべてのページでbandを差し替えます。帯、小見出し、行頭記号、キャプションのラベル、傍らの囲みの罫がすべてbandを使うので、事業報告のページは青緑、財務のページはれんが色で刷られ、理事長の手紙は基本の海の青のままです(部ごとの色)。

#5 · 表をデータから組み、最終ページの段末をそろえる

script.js · 170〜219行コード全体で見る
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()はDATA.accountsを1行ずつ損益計算書に変えます。=で始まるラベルは各年度の累計を淡い地色の上に太字で印刷します。費用はデータ上で負の値なので、Operating surplusはその累計から出てきて、手で打ち込む合計はありません。数値のないラベル(IncomeやOperating costs)は、表の幅いっぱいのイタリックのセル1つになります。結合はmergeCellsで行い、結合に必要なプレースホルダーのセルもこれが書き出します。5ページ目では、計算書が文書を締めくくる財務担当の報告の下、ページの地側にページ幅でフロートします。段末をそろえなければ、左段は12行、右段は9行になります。末尾の切りそろえで両段を11行にし、見出しの調整手段が右段にまだ足りない1行をCash and reservesの上に加えます。

レシピの全体

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

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#見出しにすき間をすべて渡す

3ページ目の2行の空きは、2行ともThe Saltings and the roofsの上に入り、リストの後には入りません。

-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

#段末そろえを切る

3ページ目の右段は2行短く終わります。5ページ目では左段が12行、右段が9行になり、計算書は1行下から始まります。

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

よくあるつまずき

つまずき

avoidWidowsは段の末尾を、avoidOrphansは段の頭を守る

Postextは2種類の孤立行に独自の名前を付けています。avoidWidows(widowMinLines、widowPenalty)は段落の1行目が段の末尾に1行だけ残るのを防ぎ、avoidOrphans(orphanMinLines、orphanPenalty)は段落の最終行が次の段の頭に1行だけ残るのを防ぎます。多くの組版の手引きはこの2つの名前を逆に使っているので、設定は効く位置で選んでください。どちらも既定で有効ですが、文字グリッド(cjk.grid)上では違います。グリッド上ではavoidWidowsが既定でオフになり、日本の地域設定ではavoidOrphansもオフになります(postext 1.28以降)。ページがグリッドの数える行数を収めるためです。どちらもペナルティとして働きます。レイアウトは、それぞれを、従った場合に生じる空行と比べて判断します。 ウィドウ、オーファン、ラント →

つまずき

結合セルにはhiddenByのプレースホルダーが要る。mergeCellsを使う

セルは行の配列内の位置で配置されるため、結合セルが広がる位置にはhiddenByを付けたプレースホルダーのセルが必要です。HTMLのように省くと、それ以降の列がすべてずれます。結合はmergeCellsで作ってください。postext 1.5からは、グリッドが不ぞろいな表はdoc.contentWarningsにraggedTableGridとして報告され、parseTSV(text, { headerRows })でヘッダー行を指定できます。 データから作る表 →

  • 最終ページの段の差が1行なら、組版職人が組むのと同じく、左段を1行長くしたまま手を加えません。末尾の切りそろえが働くのは差が2行以上のときだけです。両段を同時に終わらせたいなら、原稿を1行分長くするか短くしてください。
  • 損益計算書では費用を括弧で囲みます。正の数値を括弧付きの費用と縦にそろえるため、CodePenのサンプルでは正の数値の末尾にノーブレークスペースを置いています。等幅フォントでは閉じ括弧と同じ幅になり、表のセルは末尾のこのスペースを保ちます。

クレジット

レシピ
Ignacio Ferro
本文
書き下ろしの文章, CC BY 4.0
フォント
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