かんたんな説明
印刷と文字をテーマにした2日間の学会の、印刷されたプログラムです。時間割では1つの講演がすべての会場や2つの時間帯にまたがり、テーマごとに色が分かれています。
できあがり
ジローナで開かれる架空のタイポグラフィ学会の印刷プログラムで、カタルーニャ語で書かれています。表紙は墨色の地に、カタルーニャ語の大文字エラ・ジェミナーダ(L·L)を3つの色のモジュールで描きます。各日は76mmの墨色の帯で始まり、日付を144ptの数字で入れます。木曜日の時間割は表です。開会講演は3つの会場にまたがる墨色のセル1つを占め、ワークショップはそれぞれ2コマを取ります。一日の区切りは時間割の全幅にわたって行の頭に立ち、各発表はトラックの色のタイルに入って、キャプションの色見本が凡例になります。時間割は1ページより高いので、3ページを埋め、繰り返される見出し行の下で4ページで終わります。金曜日の短い時間割は、その日の最初のページの下部に分割されずに収まります。
このレシピが答える質問
- 見出し行、結合セル、列幅、セルごとのそろえを備えた表を作るには?
- 長い表を、見出し行を繰り返し「続く」の表示を付けて、ページをまたいで分割するには?
- 本文、キャプション、表の注に色見本(凡例の色)を加えるには?
- 「図」や「表」のラベルを文書の言語で表示するには?
- 裁ち落としまで届く色帯、大きな章番号、タイトルを備えた章扉を作るには?
手短な答え
const ROOMS = ['Sala Gran', 'Sala de les Premses', 'Aula Taller'];
const TRACKS = { T: 'tipo', D: 'digital', E: 'edicio', '*': 'ink' }; // '*': a plenary
const at = (row, c) => ({ row, col: c });
const span = (r0, c0, r1, c1) => ({ start: at(r0, c0), end: at(r1, c1) });
const lines = (code, text) => text.split(' / ').map((line, i) => { // title, then speaker
const run = i === 0 ? `**${line}**` : line;
return code === '*' ? chip(run, 'blanc') : run; // paper-white type on the ink fill
}).join('\n'); // a line break in a cell starts a new paragraph
function schedule(text) { // '11.15 | T Title / Speaker | ^' · a bare line: a part of the day
let m = { headerRowCount: 1, columnWidths: [12, 42, 42, 42], // weights of the 138 mm measure
rows: [['Hora', ...ROOMS].map((room) => ({ content: room.toUpperCase(), isHeader: true }))] };
for (const line of text.trim().split('\n')) {
const [time, ...slots] = line.split(' | ');
const r = m.rows.push(['', ...ROOMS].map(() => ({ content: '' }))) - 1; // four empty cells
if (!slots.length) { // one cell across the table; a split keeps it with the rows it heads
m = setCellContent(m, at(r, 0), chip(time.toUpperCase(), 'franja'));
m = mergeCells(m, span(r, 0, r, 3));
continue;
}
m = setCellContent(m, at(r, 0), chip(time, 'hora'));
slots.forEach((slot, i) => {
if (slot === '^') { // the session above runs on: one cell down both rows, centred in them
m = mergeCells(m, span(r - 1, i + 1, r, i + 1));
m = setAlignment(m, at(r - 1, i + 1), 'left', 'middle');
return;
}
const [, code = '', body = slot] = /^([TDE*]) (.+)$/.exec(slot) ?? [];
m = setCellContent(m, at(r, i + 1), lines(code, body));
m = setCellBackground(m, at(r, i + 1), col(TRACKS[code] ?? 'pause'));
});
if (slots.length === 1) m = mergeCells(m, span(r, 1, r, 3)); // the same for all three rooms
}
return m; // mergeCells marks the covered cells hiddenBy (gotcha: merged-cells-hiddenby)
}
材料
- 機能
- データから作る表ページをまたぐ表セルの塗り色見本インラインのチップ図の配置表スタイルキャプションのスタイルデザインした章扉段抜きの章見出し帯見出しの属性見出しスタイル表紙、扉、奥付「図」と「表」を文書の言語で独自のリソースの種類段落スタイル柱とノンブルセマンティックカラーパレット
- 種類
- Schibsted Grotesk, Unbounded, Chivo Mono (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · プログラムの各行を表の行にする
コードは上の手短な答えにあります。各日はコンテンツファイルのプレーンテキストで、1つの時間帯を1行に書きます。|が会場を区切り、文字がトラックを示し、*は墨色の塗りの全体講演を、/は題のあとの各行の始まりを示し、^は上の時間帯のセッションが続くことを示します。結合はすべてmergeCellsが行います。全体講演や休憩のようにセッションが1つだけの行は、3つの会場の列を占めます。ワークショップは自分のセルとその下のセルを占め、|のない行として書く一日の区切り(MATÍ、TARDA)は4列すべてを占めます。結合で覆われるセルはhiddenByの印を付けて表に残します。セルの列は行の中のインデックスで決まるからです(表モデルの構築)。headerRowCount: 1で会場名が見出し行になります。columnWidthsは相対的な重みで、12 + 3 × 42が138mmの行長に一致するので、時刻の列は幅12mm、各会場は42mmです。setAlignment(…, 'left', 'middle')は、各ワークショップを2行の中で上下中央に置きます。
#2 · 木曜日は次ページへ続け、金曜日は分割しない
// The built-in types in Catalan, Figura and Taula; a grid's caption goes above it.
const resourceTypes = defaultResourceTypes('ca').map((type) => ({ ...type,
...(type.id === 'table' && { captionStyle: { position: 'above' } }),
numberingTemplate: '{n}', resetOn: 'never' })); // Taula 1, Taula 2: one count, not per day
const SPLIT = { overflow: 'split', // the default; the other values are 'clip' and 'hide'
// The engine's own Catalan strings are '(cont.)' and 'Continua': these spell them out.
continuedSuffix: '(continuació)', // after the caption of every part but the first
continuesMarker: 'Continua a la pàgina següent' }; // under every part but the last
// Thursday is cited on page 2 and placed at the top, so it opens page 3 (gotcha:
// top-float-next-page) and splits; Friday goes whole to the foot of the page that cites it.
const PLACE = { dijous: { position: 'top', span: 'page' },
divendres: { position: 'bottom', span: 'page' } };
木曜日の時間割は2ページで参照され、ページの頭に置かれます。フロートは参照より上には置かれないので、時間割は3ページの頭から始まります。ページより高いため、overflow: 'split'が行と行のあいだで切ります。結合したセルの内部で切ることはありません(ページより高い表)。3ページは17.30の行とその下の案内で終わります。4ページでは見出し行と、色見本の凡例を含むキャプション全体を繰り返し、そのあとに(continuació)が続きます。注記はこの最後の部分の下にだけ印刷されます。金曜日の時間割はページの下部に置かれ、5ページでそれを参照する本文の下に収まります。defaultResourceTypes('ca')は種類にカタルーニャ語の名前、FiguraとTaulaを付けます。分割された表に対するエンジンのカタルーニャ語の文字列は(cont.)とContinuaですが、表スタイルではこの2つを省略せずに書いています。numberingTemplate: '{n}'とresetOn: 'never'で、2つの時間割を1つの通し番号でTaula 1、Taula 2と数えます。
#3 · 塗りをタイルに切り分ける
const tableStyle = { ...SPLIT, borderColor: col('paper'), borderWidth: pt(1.6), // grid rules
headerBackground: col('ink'), headerColor: col('paper'), headerFontFamily: LABEL,
headerFontSize: pt(7.5), bodyFontSize: pt(8.2),
cellPadding: mm(1.5) };
const bare = (id, extra) => ({ id, backgroundEnabled: false, borderWidth: pt(0),
paddingX: pt(0), ...extra }); // a chip that only changes the face, the size or the colour
const chipStyles = [bare('blanc', { color: col('paper') }), // the plenary's type, on ink
bare('hora', { fontFamily: LABEL, fontSize: em(0.96), bold: true }),
bare('franja', { fontFamily: LABEL, fontSize: em(0.92), bold: true, color: col('accent') }),
bare('sala')]; // keeps each room of the plan's note on one line
手短な答えのsetCellBackgroundは各セッションにトラックのパレットの色を与え、紙の色で幅1.6ptにした罫が塗りをタイルに切り分けて、白い溝を作ります(表スタイル)。表の本文セルの文字色は1つだけなので、全体講演の白い文字はチップで組みます。そのスタイルが色を設定し、チップの塗り、枠線、左右の内側余白を切ります。時刻と一日の区切りもChivo Monoのチップです(チップスタイル)。チップは行をまたいで分割されません。全体講演の題と講演者の行は、3会場分のセルの中でそれぞれ1行に収まります。平面図の注記では、salaチップが文字をそのままにして各室の番号と名前を1行に保ちます。語の間にノーブレークスペースを入れた場合と同じです。
#4 · 各日を帯で始める
const BAND = 76, STRIP = 8, AIR = 7; // mm: band from the trim, its strip of modules, air below
const text = (id, content, family, size, color, placement, extra) => ({ kind: 'text', id,
content, fontFamily: family, fontSize: pt(size), color: col(color), placement, align: 'left',
overflow: 'wrap', ...extra }); // a long line wraps, in the running heads too
const pin = (to, edge, x, y, size) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) },
...(size && { size }) });
const caps = (size) => ({ fontWeight: 500, textTransform: 'uppercase',
letterSpacing: pt(size * 0.18) });
const NUMERAL = 144; // pt
// mm: Unbounded 800's 1 at 144 pt starts its ink 0.76 mm into its box, the date's first capital
// at 8 pt 0.1 to 0.2 mm into its own (P 0.19, S 0.09): 0.6 mm to the left lines up the two inks
const BEARING = 0.6;
const BASELINE = 0.8; // a design line's baseline sits 0.8 down its box (lineHeight 1)
const opener = { enabled: true, minHeight: mm(BAND - PAGE.top + AIR), slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('ink') },
placement: pin('bleed', 'top-left', 0, 0, { width: 'fill', height: mm(BAND) }) },
{ kind: 'image', id: 'strip', resourceId: 'strip', placement: pin('page', 'top-left', 0,
BAND - STRIP, { width: mm(PAGE.w), height: mm(STRIP) }) }, // on the band's foot
text('date', '{attr.date}', LABEL, 8, 'edicio', pin('container', 'top-left', 0, 0), caps(8)),
text('numeral', '{attr.day}', DISPLAY, NUMERAL, 'paper', pin('#date', 'below', -BEARING, 1),
{ fontWeight: 800, lineHeight: 1 }), // a 144 pt line box
text('title', '{titleText}', DISPLAY, 26, 'paper', // its baseline level with the numeral's
pin('#numeral', 'right-of', 5, BASELINE * (NUMERAL - 26) * PT),
{ fontWeight: 700, lineHeight: 1 }),
] } };
第1レベルの見出しのデザインが帯を描きます。塗り足しの端から76mmの深さの箱で、その下端にモジュールが帯状に並びます。日付は見出しのdate属性から、数字はdayから取ります。144ptのUnbounded 800の1は字面が箱の0.76mm内側から始まり、日付の最初の大文字は自分の箱の0.1〜0.2mm内側から始まります。そこで数字を0.6mm左へ動かし、日付、数字、本文の字面の始まりを互いに0.2mm以内にそろえます。曜日名は数字の右に置き、BASELINE × (144 − 26)pt下げて2つのベースラインを合わせます。lineHeight: 1のデザインのテキストは、ベースラインが箱の上から0.8の位置にあるからです。minHeightは帯の下7mmまでのページを確保し、ベースライングリッドがその確保を14行に切り上げるので、本文の最初の行の箱は帯の10.2mm下から始まります。AIR = 0にすると、帯の下端より下に出る数字自体の箱が高さを決め、本文は帯の5.6mm下から始まります。
#5 · 講演者の紹介の折り返しを字下げする
const paragraphStyles = [
{ id: 'bio', hangingIndent: mm(4) }, // the name at the column edge, the lines under it 4 mm in
{ id: 'colophon', fontFamily: LABEL, fontSize: pt(7.4), lineHeight: pt(LEAD * 0.75),
textAlign: 'left', color: col('muted'), firstLineIndent: pt(0), marginTop: pt(LEAD) },
];
講演者はそれぞれ:::paragraphs{style="bio"}ブロックの1段落です。太字の名前は段の端から始まり、その下の行は4mm下げるので、索引のように名前が段の下へ並びます(段落スタイル)。
レシピの全体
// ═══ Postext Cookbook · Nº 053 · Conference programme with a merged schedule grid ═══════
// https://postext.dev/en/cookbook/conference-programme
// Code: MIT · Text: original, in Catalan (CC BY 4.0) · Drawings: generated in code (CC BY 4.0)
// Fonts: Schibsted Grotesk, Unbounded, Chivo Mono (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage,
defaultResourceTypes, mergeCells, setCellContent, setCellBackground, setAlignment,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'conference-programme';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#1d1b24', paper: '#ffffff', // a violet near-black; type on the ink fills
tipo: '#b09cf2', digital: '#4fc7bb', edicio: '#f4b43a', // the three tracks: fills and swatches
pause: '#ecebf1', // registration, breaks and meals
accent: '#6a3ed3', // kickers, caption labels, the parts of the day
muted: '#67636f', // running heads and notes
};
// Each colour carries its hex and the palette entry it follows.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.accent }) // defaults' id
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, DISPLAY, LABEL] = ['Schibsted Grotesk', 'Unbounded', 'Chivo Mono'];
const PAGE = { w: 170, h: 240, top: 22, bottom: 20, inner: 17, outer: 15 }; // mm, mirrored
const LEAD = 13; // pt: the body's leading and baseline grid
const PT = 25.4 / 72; // mm in a point
const chip = (text, style) => `:chip[${text}]{style="${style}"}`;
// #region answer: a day's schedule as a table with merged cells, track fills and a head row
const ROOMS = ['Sala Gran', 'Sala de les Premses', 'Aula Taller'];
const TRACKS = { T: 'tipo', D: 'digital', E: 'edicio', '*': 'ink' }; // '*': a plenary
const at = (row, c) => ({ row, col: c });
const span = (r0, c0, r1, c1) => ({ start: at(r0, c0), end: at(r1, c1) });
const lines = (code, text) => text.split(' / ').map((line, i) => { // title, then speaker
const run = i === 0 ? `**${line}**` : line;
return code === '*' ? chip(run, 'blanc') : run; // paper-white type on the ink fill
}).join('\n'); // a line break in a cell starts a new paragraph
function schedule(text) { // '11.15 | T Title / Speaker | ^' · a bare line: a part of the day
let m = { headerRowCount: 1, columnWidths: [12, 42, 42, 42], // weights of the 138 mm measure
rows: [['Hora', ...ROOMS].map((room) => ({ content: room.toUpperCase(), isHeader: true }))] };
for (const line of text.trim().split('\n')) {
const [time, ...slots] = line.split(' | ');
const r = m.rows.push(['', ...ROOMS].map(() => ({ content: '' }))) - 1; // four empty cells
if (!slots.length) { // one cell across the table; a split keeps it with the rows it heads
m = setCellContent(m, at(r, 0), chip(time.toUpperCase(), 'franja'));
m = mergeCells(m, span(r, 0, r, 3));
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#時間割の角を丸める
分割された表は、最初の部分(3ページ)の上の角と、最後の部分(4ページ)の下の角を丸めます。4ページでは時刻の列に塗りがないので、見えるのは右の角だけです。
- cellPadding: mm(1.5) };
+ cellPadding: mm(1.5), borderRadius: mm(2.5) };#日ごとに時間割に番号を振る
組み込みのタイプと同じくレベル1の見出しごとに数えると、Taula 1.1とTaula 2.1になり、平面図はFigura 2.1になります。表紙のスタイルは番号を振らないので、木曜日が見出し1です。
- numberingTemplate: '{n}', resetOn: 'never' })); // Taula 1, Taula 2: one count, not per day
+ numberingTemplate: '{h1}.{n}', resetOn: 'h1' })); // Taula 1.1, Taula 2.1: per dayよくあるつまずき
つまずき
'top'のフロートは参照ページの先頭を許さない限り次のページに置かれる
既定では、フロートが自分の参照より上に置かれることはありません。そのため、Nページで参照したページ幅の'top'フロートはN+1ページの頭に置かれます。リソースまたはその種類のdefaultPlacementにplacement.citingPage: trueを設定すると(本全体ならlayout.floatsAtCitingPage、postext 1.25から)、layout.maxTopFraction以内に収まり参照行がそのページに残る場合は代わりにNページの先頭に置かれ、参照より前の本文はその下に送られます。章の最初のページと強制改ページの後のページの先頭には置かれません。その場合は次のページに置かれ、'auto'または'bottom'なら参照したページの下端に入れられます。 図の配置 →
クレジット
- 本文
- The programme’s Catalan text, both schedules included, written for this recipe, and the cover, band and floor-plan drawings, generated in code · Ignacio Ferro · CC BY 4.0
- フォント
- Schibsted Grotesk (SIL OFL 1.1) · Unbounded (SIL OFL 1.1) · Chivo Mono (SIL OFL 1.1)


