かんたんな説明
表紙、マーク式の解答欄、書き込み用の罫線ページが付いた4ページの歴史の試験です。設問と小問の番号の付け方と、各問の配点の示し方がわかります。
できあがり
アメリカ南北戦争をテーマにした歴史の模擬試験の第2部を、USレター判4ページの冊子に組みます。表紙は1863の年号を輪郭線で描いた深紅の帯で、その下に受験者欄、2段組みの注意事項、Section A用の文字入りマーク欄が並びます。2ページ目には多肢選択問題が10問あり、それぞれの後に4つの選択肢が続きます。どの選択肢も、マーク欄と同じ文字入りのマークで始まります。3ページ目はゲティスバーグ演説をSource Aとして組み、それについての設問を11、a)、i)と番号付けし、小問ごとの配点を右の余白にそろえたチップで示します。4ページ目は解答用に、本文2行ごとに1本の罫線を引き、罫線の各組は小問の番号で始まります。表紙以降のページにはどれもノンブルと採点者用の罫線付き余白があり、その中で唯一の右ページには「Turn over」と入ります。
このレシピが答える質問
- 記入線、解答欄、語群、チェックリストのあるワークシートのページを作るには?
- リストをカスタマイズするには(レベルごとの記号、(a)/(i)の番号、タスクのチェックボックス、グリッドに乗る間隔)?
- キーボードのキー、タグ、練習問題の語群などのインラインのチップを作るには?
- 1つの文書の中で、複数の表を異なるスタイル(塗り、縞模様のセル、角丸の枠)にするには?
- 章扉や白ページで柱を隠したり、空白の偶数ページを部の色で塗ったりするには?
手短な答え
// A table row is one line (the table's size × the body's leading ratio) plus cellPadding above
// and below: at the body size, (ROW − LEAD) / 2 of padding makes every row ROW deep, so the
// rules keep to the text's 15 pt grid, 10.6 mm apart: room for handwriting.
const ROW = 2 * LEAD; // pt
const lines = { id: 'lines', rules: 'horizontal', // a rule on the top and foot of every row
borderColor: col('rule'), borderWidth: pt(0.5), bodyFontFamily: LABEL, bodyFontSize: pt(BODY),
bodyColor: col('crimson'), cellPadding: pt((ROW - LEAD) / 2) };
// Every table in this paper is set 'here': where its ::resource directive stands in the text.
const table = (id, styleId, model) => ({ id, typeId: 'form', kind: 'table', createdAt: 0,
updatedAt: 0, placement: { position: 'here' }, table: { styleId, model } });
// One table per answer, the part's number in its first margin cell.
const answerLines = (id, part, rows) => table(id, 'lines', { columnWidths: [1, 5], rows: Array
.from({ length: rows }, (_, i) => [{ content: i ? '' : `**${part}**` }, { content: '' }]) });
材料
- 機能
- 番号付きリストインラインのチップタブストップとリーダー名前付きの表スタイルデータから作る表独自のリソースの種類その場に置く図セルの塗りキャプションのスタイル改ページと改段ページの役割ごとの柱柱とノンブル見出しスタイル節ごとのページ構成デザインした章扉見出しの属性ページデザインの画像囲み囲みの中や本文中の段組み段落スタイル
- 併用する機能
- リソースとしての図と表明示的な縦のアキ
- 種類
- PT Serif, Inter Tight (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · 設問に番号を付け、選択肢を吊るす
const [NUMBER, GAP] = [12.5, 6]; // pt: the question numbers' size; number to text
const orderedLists = { fontFamily: LABEL, color: col('ink'), // bold, by default
separatorColor: col('crimson'), gap: pt(GAP), marginTop: pt(LEAD / 2), marginBottom: pt(0),
itemSpacing: pt(5), numberWidth: 'level', // 5 pt to the options or next part; text after '10.'
levels: [{ level: 1, fontSize: pt(NUMBER) }, // 'arabic' and '.', the defaults
{ level: 2, numberFormat: 'lower-alpha', separator: ')' },
{ level: 3, numberFormat: 'lower-roman', separator: ')' }] };
// Options: a bulletless item at the questions' depth, '10.' plus GAP in (boxes set their own).
const width = (s) => { const ctx = new OffscreenCanvas(1, 1).getContext('2d');
ctx.font = `700 ${NUMBER}pt "${LABEL}"`; return ctx.measureText(s).width * 0.75; }; // pt
const unorderedLists = () => ({ gap: pt(0), marginTop: pt(0), marginBottom: pt(0),
itemSpacing: pt(LEAD), // after the options: a line before the next question
indent: pt(width('10') + width('.') + GAP), levels: [{ level: 1, bulletChar: '' }] });
orderedListsの各レベルは、それぞれのnumberFormatとseparatorを選びます。separatorColorはピリオドと括弧をアクセント色で塗り、番号はインキの色のまま残します(番号付きリスト)。numberWidth: 'level'にすると、番号は同じ階層でいちばん幅の広い番号に合わせて右そろえになるので、どの設問の本文も23 pt字下げした位置から始まります。'10.'の17 ptにGAPを足した値です。4つの選択肢は、bulletCharを空にした箇条書きの1項目で、設問の下に入れ子にせず、設問と同じ階層に置きます。その本文はリストのindentの位置、つまり番号用の書体で測った'10.'にGAPを足した位置から始まるので、どの書体でも選択肢が設問の最初の文字の下にそろいます。囲みの中のリストは文書の字下げを受け継ぐため、指示の囲みはindent: pt(0)を指定します。同じ階層の2項目の間隔は前の項目のitemSpacingで、番号付きの項目の後は5 pt、選択肢の行の後は15 ptです。設問の下に入れ子にすると、選択肢の行は前後とも設問のリストの5 ptになります。
#2 · マークと配点をチップで作る
// A chip is 0.8 em above the baseline and 0.25 em below, plus paddingY and the border on each
// side: 1.29 em and two borders. One capital is 0.63–0.72 em wide, so paddingX 0.3 em (and the
// same two borders) squares the box; a radius over half its smaller side is clamped to that half.
const chip = (id, look) => ({ id, fontFamily: LABEL, fontSize: em(0.8), bold: true,
paddingY: em(0.12), ...look });
const bubble = (id, fill, ink, edge = 'crimson') => chip(id, { color: col(ink), paddingX: em(0.3),
background: col(fill), borderColor: col(edge), borderWidth: pt(0.7), borderRadius: em(1) });
const chipStyles = [bubble('bubble', 'paper', 'crimson'), // first: a bare :chip[A] takes it
bubble('filled', 'ink', 'paper', 'ink'), chip('marks', { color: col('crimson'),
background: col('blush'), borderWidth: pt(0), paddingX: em(0.45), gap: em(0.5) })];
チップは行の中のボックスで、その内側で改行が起きることはありません(インラインのチップ)。中にキャピタルが1文字だけなら、paddingX: em(0.3)でボックスの幅が高さとほぼ同じになります。マーク欄では高さ4.7 mmに対して幅4.5〜4.8 mmです。borderRadius: em(1)はボックスの半分より大きく、チップの角丸は短い辺の半分に制限されるので、両端は完全な丸になります。styleのないチップはchipStylesの最初の項目を取るので、80個のマーク(マーク欄に40、選択肢に40)は:chip[A]のような素のチップです。スタイル名を指定するのは、注意事項にある塗りつぶしの例と配点だけです。配点は右端にそろいます。小問はそれぞれチップの前の:tabで終わり、本文の唯一のタブ位置が行長の終わりにあってalign: 'end'を指定しているので、チップはそこで終わります(タブとタブ位置)。設問のリスト項目は本文のタブ位置を使うので、a)のチップとi)のチップは同じ位置で終わります。最後の行にチップの入る余地がない小問は、最後の語をチップと一緒に次の行へ送ります。
#3 · フォームごとに専用の表スタイルを与える
// No table has a header row; the flag keeps the default grey fill off one added later.
const form = { bodyFontFamily: LABEL, borderRadius: mm(2), headerBackgroundEnabled: false };
const tableStyles = [lines,
{ ...form, id: 'candidate', rules: 'grid', borderColor: col('rule'), borderWidth: pt(0.75),
bodyFontSize: pt(7.5), bodyColor: col('crimson'), cellPadding: mm(1.8) },
// No rules: the tint of each cell meets its neighbours' and the grid reads as one panel.
{ ...form, id: 'grid', rules: 'none', bodyBackgroundEnabled: true,
bodyBackground: col('tint'), bodyFontSize: pt(11.5), cellPadding: mm(1.4) }];
const cell = (content, extra) => ({ content, align: 'center', verticalAlign: 'middle', ...extra });
// The MARK cell sets the row's depth: three lines, the blank one a no-break space.
const candidate = table('candidate', 'candidate', { columnWidths: [4.2, 1.2, 2, 1.3], rows: [[
...t({ en: ['NAME', 'CLASS', 'CANDIDATE NUMBER'], es: ['NOMBRE Y APELLIDOS', 'GRUPO',
'N.º DE EXAMEN'] }).map((l) => cell(`**${l}**`, { align: 'left', verticalAlign: 'top' })),
cell(`**${t({ en: 'MARK', es: 'NOTA' })}**\n\u00A0\n**/ ${t({ en: '25', es: '10' })}**`,
{ align: 'right', background: col('tint') })]] });
const GROUP = ['A', 'B', 'C', 'D'].map((l) => cell(`:chip[${l}]`)), num = (n) => cell(`**${n}**`);
const grid = { ...table('grid', 'grid', { columnWidths: [0.7, 1, 1, 1, 1, 1.4, 0.7, 1, 1, 1, 1],
rows: [1, 2, 3, 4, 5].map((n) => [num(n), ...GROUP, cell(''), num(n + 5), ...GROUP]) }),
caption: t({ en: '**Section A answer grid**', es: '**Parte A: plantilla de respuestas**' }) };
// The grid's title is its caption: a heading would stand a body line off any 'here' table.
const captionStyle = { fontFamily: LABEL, fontSize: pt(9.4), color: col('crimson'),
position: 'above', gap: mm(1.6) }; // the rubric's size
受験者欄、マーク欄、解答用の罫線は3つのtableStylesで、表ごとにstyleIdで選びます(名前付きの表スタイル)。手短な答えの解答用の罫線は、rules: 'horizontal'と、各行を本文2行分の深さにする内側余白を使うので、罫線はどれも前の罫線の30 pt(10.6 mm)下、つまり本文の15 ptのグリッドの2行ごとに落ちます。MARKのセルの空いた中央の行にはノーブレークスペースを入れています。空の行や通常のスペースだけの行は高さを加えないからです。このセルは3行の深さになり、行全体を14.4 mmで組みます。2行なら10.8 mmです。マーク欄には罫線を引きません。各セルの塗りが隣のセルの塗りとつながり、欄全体が1枚のパネルに見えます。そのタイトルは、表の1.6 mm上に組むキャプションです(キャプションスタイル)。見出しにすると、少なくとも本文1行分(5.3 mm)高くなります。'here'に置く表は、どれもその分の空きを上に確保するからです。formタイプのcaptionPrefixは空なので、タイトルの前に「Form 1.」のようなラベルは付きません。
#4 · 表紙を見出しの属性から描く
const BAND = 116; // mm: the crimson band, bled off the top and both sides
const YEAR = { cap: 62, cut: 12, pad: 2 }; // mm: the digits' cap height; the band cuts 12 off
// span 'page' makes the cover an opener page, which the body pages' furniture skips.
const cover = { id: 'cover', span: 'page', margins: { right: mm(LEFT) }, // forms full width
advancedDesign: { enabled: true, slot: { elements: [ // the date line sets the height
{ kind: 'box', id: 'band', style: { backgroundColor: col('crimson') },
placement: at(0, 0, { width: mm(PAGE.w), height: mm(BAND) }) },
// Design text has no outline, so the year is an image, cut off by the band's foot.
{ kind: 'image', id: 'year', resourceId: 'year', placement: at(0, BAND - YEAR.cap
+ YEAR.cut - YEAR.pad, { width: mm(PAGE.w), height: mm(YEAR.cap - YEAR.cut + YEAR.pad) }) },
text('session', '{attr.session}', LABEL, 8.5, 600, 'blush', at(LEFT, 14), tag),
// 0.9 mm to the left: the H's side bearing at 64 pt (84 of 2048 units), so its stem aligns.
text('title', '{titleText}', LABEL, 64, 800, 'paper', at(LEFT - 0.9, 19), { lineHeight: 1 }),
text('paper', '{attr.paper}', LABEL, 15, 700, 'paper', at(LEFT, 44)),
text('topic', '{attr.topic}', TEXT, 15, 400, 'blush', at(LEFT, 52), { italic: true }),
text('date', '{attr.date}', LABEL, 9.5, 700, 'ink', at(LEFT, BAND + 6))] } } };
表紙は# History {style="cover" …}という1つの見出しで、そのスタイルが帯、年号、見出しの属性で埋める4行のテキストを描きます。span: 'page'があるとページは章扉として扱われるので、本文ページの余白の罫、ノンブル、「Turn over」はこのページに出ず、地には注意書きが印刷されます。これがないと、表紙もほかと同じ本文ページになります。スタイルのmarginsは表紙の段をフォーム用に168 mmいっぱいまで広げ、次の見出し、スタイルなしのレベル1が、本文ページを134 mmの行長に戻します。
#5 · ノンブルと「Turn over」を表紙から外す
const [MARGIN, FOOT] = [LEFT + MEASURE + 7, -13]; // mm: the margin rule, 7 off the text; the foot
const body = { pages: 'body', ...tag }; // body pages only: never the cover
const NOTE = t({ en: 'Do not write in this margin', es: 'No escribas en este margen' });
const header = { elements: [
text('running', '{title} · {chapterTitle}', LABEL, 7.5, 600, 'muted', at(LEFT, 12), body),
{ kind: 'rule', id: 'margin', direction: 'vertical', pages: 'body', color: col('rule'),
thickness: pt(0.75), placement: at(MARGIN, TOP, { height: mm(PAGE.h - TOP - BOTTOM) }) },
text('note', NOTE, LABEL, 7.5, 600, 'muted', at(MARGIN + 3, TOP, { width: mm(28) }),
{ ...body, lineHeight: 1.3 })] };
const footer = { elements: [
text('notice', '{attr.notice}', LABEL, 8.5, 700, 'crimson', at(0, FOOT, { width: mm(PAGE.w) },
'bottom-left'), { pages: 'opener', align: 'center', ...tag }), // from the cover's H1
text('folio', '{pageNumber}', LABEL, 9, 700, 'ink', at(LEFT, FOOT, { width: mm(MEASURE) },
'bottom-left'), { ...body, align: 'center' }), // centred under the text
text('turn', t({ en: 'Turn over ›', es: 'Pasa la página ›' }), LABEL, 9, 700, 'ink', // rectos
at(-RIGHT, FOOT, null, 'bottom-right'), { ...body, parity: 'odd', align: 'right' })] };
本文ページの柱類の要素はすべてpages: 'body'を指定しているので、章扉である表紙には自分専用の注意書き(pages: 'opener')だけが出ます。そのため各セクションは:::pagebreakと、breakBeforeのない見出しで始めます。改ページする見出しはそのページを章扉にするので、2ページ目と3ページ目のノンブル、柱、余白が消えてしまいます。parity: 'odd'は「Turn over」を奇数ページにとどめます。偶数ページは、すでに次のページと向き合っているからです。
レシピの全体
// ═══ Postext Cookbook · Nº 049 · Exam paper with an answer sheet ═════════════════
// https://postext.dev/en/cookbook/exam-paper
// Code: MIT · Text: Lincoln (PD); questions, Spanish translation (CC BY 4.0) · Art: in code
// Fonts: PT Serif, Inter Tight (SIL OFL 1.1) · Needs postext ≥ 1.34.0
import {
buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage, inlineSvgFonts,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'exam-paper';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#1b1a1f', paper: '#ffffff', muted: '#6b6466', // heads, credits: 5.8:1
crimson: '#9b1c31', // the one accent: cover, numbering, bubbles, marks (8.1:1 on white)
blush: '#f3cdd4', tint: '#fbeff1', // type on the band, marks chips; the grid, the rubric box
rule: '#b9aeb0' }; // answer lines and hairlines
// col(id): a colour linked to its palette entry, with the entry's hex beside the id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults are linked to 'main-color': point it at the accent.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.crimson })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, LABEL, PAGE] = ['PT Serif', 'Inter Tight', { w: 215.9, h: 279.4 }]; // US Letter
const [TOP, BOTTOM, LEFT, MEASURE] = [22, 24, 24, 134]; // mm; 134 mm: about 75 characters
const RIGHT = PAGE.w - LEFT - MEASURE; // 57.9 mm: the examiner's margin, never mirrored
const [BODY, LEAD] = [11, 15]; // pt: text size and leading, the grid every line keeps to
const at = (x, y, size, edge = 'top-left') => ({ anchor: { to: 'page', edge },
offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });
const text = (id, content, family, size, weight, color, placement, extra) => ({ kind: 'text',
id, content, fontFamily: family, fontSize: pt(size), fontWeight: weight, color: col(color),
align: 'left', overflow: 'wrap', placement, ...extra });
const tag = { textTransform: 'uppercase', letterSpacing: pt(1.4) }; // 0.16–0.19 em
const small = { fontFamily: LABEL, fontSize: pt(7.5), lineHeight: pt(10), color: col('muted') };
// #region answer: ruled answer lines: a table whose rows are two body lines deep
// A table row is one line (the table's size × the body's leading ratio) plus cellPadding above
// and below: at the body size, (ROW − LEAD) / 2 of padding makes every row ROW deep, so the
// rules keep to the text's 15 pt grid, 10.6 mm apart: room for handwriting.
const ROW = 2 * LEAD; // pt
const lines = { id: 'lines', rules: 'horizontal', // a rule on the top and foot of every row
borderColor: col('rule'), borderWidth: pt(0.5), bodyFontFamily: LABEL, bodyFontSize: pt(BODY),
bodyColor: col('crimson'), cellPadding: pt((ROW - LEAD) / 2) };
// Every table in this paper is set 'here': where its ::resource directive stands in the text.
const table = (id, styleId, model) => ({ id, typeId: 'form', kind: 'table', createdAt: 0,
updatedAt: 0, placement: { position: 'here' }, table: { styleId, model } });
// One table per answer, the part's number in its first margin cell.
const answerLines = (id, part, rows) => table(id, 'lines', { columnWidths: [1, 5], rows: Array
.from({ length: rows }, (_, i) => [{ content: i ? '' : `**${part}**` }, { content: '' }]) });
// #endregion
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#A4判で印刷する
帯、年号、余白の罫線、注意書きはPAGEからサイズを取るので、A4判にするには1行を変えるだけです。表紙の各ブロックは位置を保ち、マーク欄の下の白い部分が、どちらの版でも17.6 mm広がります。
-const [TEXT, LABEL, PAGE] = ['PT Serif', 'Inter Tight', { w: 215.9, h: 279.4 }]; // US Letter
+const [TEXT, LABEL, PAGE] = ['PT Serif', 'Inter Tight', { w: 210, h: 297 }]; // A4#語群やチェックリストを足す
語群、空欄、塗りつぶす丸もチップで作れます。解答欄と語群を備えたワークシートは、入れ子の囲みに黄色のチップの語群を組み、各行を空の丸で始めるチェックリストを置いています。
よくあるつまずき
- 設問の小問の間に解答用の罫線を挟むと、そのリストが分かれます。表の後のリストは新しい並びとして始まり、並びはそれぞれ自分の中でいちばん幅の広い番号に合わせて番号を右そろえにするので、ii)の本文がi)の本文より1 mm右から始まってしまいます。ここでは解答を専用のページに置いているので、どの小問も1つのリストに収まっています。
クレジット
- 本文
- The Gettysburg Address (19 November 1863), text of the Bliss copy · Abraham Lincoln · パブリックドメイン
- The questions, the instructions and the Spanish translation of Source A · Ignacio Ferro · CC BY 4.0
- フォント
- PT Serif (SIL OFL 1.1) · Inter Tight (SIL OFL 1.1)


