かんたんな説明
8歳の子ども向けの、植物のつくりを学ぶ理科のワークシートです。問いごとに下に答えを書く欄があり、一部の文には、語のリストから選んで埋める空欄があります。
できあがり
8歳の子ども向けの架空のシリーズ『Seedlings Science』のワークシート3Aを、200 × 260 mmの4ページに片面刷りで組みます。若葉色の帯には、黄色い単元のピル、タイトル、名前と日付を書く白い欄が載ります。その横では、白い円に入った水彩のエンドウの6つの部位に黄色で番号が振られています。この水彩画は拡散モデルで生成したもので、最初から円に収めた状態で、帯の端で接する2枚のJPEGとして用意しています。上の1枚は四隅が帯の緑、下の1枚は白です。番号と引出線は画像の上にコードで描きます。どの活動も、淡い緑のカードの上に番号付きの見出しを立てます。カードには、小さな灰色の促しの言葉と数行分の余白のある白い解答欄、黄色いチップの語群、文の中の枠線の空欄、食べ物と植物の部位を結ぶ表、色を塗る丸のチェックリストが入ります。各解答欄は問いの2 mm下、次の要素の5 mm上に置き、どのカードもそのページで次に来るものの9 mm上で終わります。本文は、SILが文字を学ぶ子どものために設計したAndikaで組みます。
このレシピが答える質問
- 解答欄を含むワークシートのカードのように、囲みを正確な間隔で入れ子にするには?
- 記入線、解答欄、語群、チェックリストのあるワークシートのページを作るには?
- キーボードのキー、タグ、練習問題の語群などのインラインのチップを作るには?
- 表のセルに画像やアイコンを入れるには?
手短な答え
// In the Markdown a box inside a box is a fence inside a fence (each ::: closes one):
// :::callout{type="card"}
// What is inside the pea pods?
// :::callout{type="answer"}
// Write here ← the prompt first: a :::space that opens a box is dropped
// :::space{lines=3} (gotcha: space-dropped-box-top)
// :::
// :::
const [ASK, AFTER, HEAD, NEXT] = [2, 5, 3, 9]; // mm: question→box, box→next, heading→card
const card = {
id: 'card', background: col('tint'), borderRadius: mm(4),
padding: { top: mm(4), right: mm(5), bottom: mm(5), left: mm(5) },
marginTop: mm(HEAD), marginBottom: mm(NEXT), // NEXT: under a card, to whatever follows
// Off the grid, or what follows a card drops to the next grid line. Only the outer card can
// set it: a nested box ignores snapToGrid, span and placement (gotcha: nested-callout-limits).
snapToGrid: false,
body: { paragraphSpacing: false }, // the boxes' margins do all the spacing
lists: { bulletChar: '', // no bullet: in the checklist a circle chip opens each item
gap: mm(2), itemSpacing: pt(7) }, columnGap: mm(6),
};
// A nested box's margins collapse with its neighbours', the larger winning (ASK, AFTER); the
// last box's marginBottom falls inside the card's padding instead of adding to it.
const nested = (id, look) => ({ id, background: col('paper'), borderRadius: mm(2.5),
marginTop: mm(ASK), marginBottom: mm(AFTER), ...look });
const answer = nested('answer', { border: { enabled: true, color: col('rule'), width: pt(0.75) },
padding: { top: mm(1.6), right: mm(3), bottom: mm(2), left: mm(3) },
// A small grey prompt on a full 17 pt line; :::space counts in these body lines.
body: { fontFamily: LABEL, fontSize: pt(8), color: col('muted') } });
const bank = nested('bank', { title: t({ en: 'Word bank', es: 'Banco de palabras' }),
padding: { top: mm(2.2), right: mm(3), bottom: mm(2.4), left: mm(3) },
titleStyle: { fontFamily: LABEL, fontSize: pt(7.5), fontWeight: 600, color: col('leaf'),
textTransform: 'uppercase', letterSpacing: pt(1.3), gap: mm(1.6) } });
// config() plugs in all three: calloutStyles: [card, answer, bank].
材料
- 機能
- 入れ子の囲み意図してグリッドを外すインラインのチップ囲み囲みの中や本文中の段組み明示的な縦のアキ見出しスタイル番号付き見出し番号のない章デザインした章扉ページデザインのテキスト・罫・ボックスページデザインの画像見出しの属性タイトル内の改行名前付きの表スタイル表のセル内の画像独自のリソースの種類その場に置く図箇条書きとチェックリスト番号付きリスト
- 種類
- Andika, Baloo 2, Fredoka (SIL OFL 1.1)
- 素材
plant-1092.jpgplant-foot-1092.jpg- The pea plant on the opener, a watercolour (top of the disc) (Generated With Diffusion Models, オリジナル)
- The pea plant’s roots, the foot of the same watercolour below the band (Generated With Diffusion Models, オリジナル)
- The plant's leader lines, the six food icons and the star, drawn in code in the page’s palette (Ignacio Ferro, MIT)
作り方
#1 · 見出しもグリッドから外す
headings: { fontFamily: DISPLAY, snapToGrid: false, // or what follows snaps back to the grid
balancing: { enabled: false }, // no extra space above headings to fill out a page
levels: [
// parity 'any': a sheet opens the next page, on either side.
{ level: 1, span: 'page', breakBefore: { enabled: true, parity: 'any' },
marginTop: pt(0), marginBottom: pt(0), advancedDesign: opener() },
{ level: 2, numberingTemplate: '{2}', marginTop: mm(0), marginBottom: mm(0),
advancedDesign: activity },
] },
手短な答えでは、各囲みのアキが隣のアキと相殺され、大きいほうが採用されます。語群の5 mmはその下のリストの上の2 mmに勝ち、最後の解答欄の5 mmは、カードの下内側余白5 mmに足されずにその中に収まります。グリッドに乗せたままだと、レベル2の見出しは円の8.6 mmではなく10.8〜14.1 mmを確保します。見出しの後に続くものが次の17 ptの行に吸着し直すからです。headings.snapToGrid: falseで8.6 mmに保ちます。入れ子のスタイルにsnapToGridを設定しても何も変わりません。グリッドから外せるのは外側のカードだけです(入れ子の囲み)。段末そろえはオフにしています。段末そろえはページを埋めるために見出しの上にスペースを足すので、2ページ目では活動3の上が9 mmではなく33 mmになってしまいます。
#2 · 空欄はすべてチップで作る
const chip = (id, fill, look) => ({ id, fontFamily: LABEL, background: col(fill),
borderWidth: pt(0), borderColor: col('leaf'), borderRadius: em(1), ...look });
// An empty chip, :chip[ ], is a box of padding and outline alone. It is a band 1.25 em tall,
// so paddingX ROUND makes it a circle.
const [ROUND, OUTLINE] = [em(0.625), pt(0.9)];
// A blank is all padding, 2 × paddingX wide and 19.6 pt tall: taller than the 17 pt line, so
// the card's itemSpacing sets its items 24 pt apart (gotcha: chip-overlap).
const blank = (id, width) => chip(id, 'paper', { borderWidth: OUTLINE, borderRadius: mm(1.4),
paddingX: mm(width / 2), paddingY: em(0.12), fontSize: em(1.15) });
const chipStyles = [
chip('word', 'sun', { bold: true, paddingX: em(0.6), paddingY: em(0.08), gap: em(0.45) }),
blank('blank', 34), blank('wide', 38), // mm: in a sentence; alone in a column
chip('dot', 'leaf', { paddingX: ROUND, fontSize: em(0.6) }),
chip('tick', 'paper', { borderWidth: OUTLINE, paddingX: ROUND, fontSize: em(1.1), gap: em(0.5) }),
];
チップは行の中の分割されない箱で、その内側余白は行を高くせずに行の外まで塗られます。語群は、入れ子にしたbankの囲みに並べたチップの列です。空欄、線で結ぶ点、色を塗る丸もチップで、どれも:chip[ ]と書きます。スペース1つだけのチップは、内側余白と枠線だけの空の箱になります(インラインのチップ)。幅はpaddingXで決めます。空欄は文の中では34 mm、段に単独で置くときは38 mmで、丸には高さ1.25 emの半分を左右それぞれに与えます。チェックリストでは、箇条書きの記号の位置に丸が立ちます(bulletChar: '')。空欄は19.6 ptで17 ptの行より高いので、1つずつ専用のリスト項目に入れ、次の項目と24 pt離しています。
#3 · 見出しのデザインで活動に番号を振る
const DISC_H2 = 8.6; // mm: the disc and the title are this tall, so the heading reserves this
const numberDisc = { kind: 'text', id: 'num', content: '{number}', // numberingTemplate '{2}'
fontFamily: DISPLAY, fontSize: pt(15), fontWeight: 800, color: col('paper'),
box: { backgroundColor: col('leaf'), borderRadius: mm(DISC_H2 / 2) }, // centred both ways
placement: { anchor: { to: 'container', edge: 'top-left' },
size: { width: mm(DISC_H2), height: mm(DISC_H2) } } };
const activityTitle = { kind: 'text', id: 'title', content: '{titleText}',
fontFamily: DISPLAY, fontSize: pt(17), fontWeight: 700, color: col('ink'), align: 'left',
overflow: 'wrap', placement: { anchor: { to: '#num', edge: 'right-of' },
offset: { x: mm(3) }, size: { width: mm(140), height: mm(DISC_H2) } } };
const activity = { enabled: true, slot: { elements: [numberDisc, activityTitle] } };
// ## How did I do? {style="review"} is not an activity: it has no number and a star for a disc.
const review = { id: 'review', numbered: false, advancedDesign: { ...activity, slot: {
elements: [{ kind: 'image', id: 'num', resourceId: 'star', placement: numberDisc.placement },
activityTitle] } } };
advancedDesignを指定したレベル2の見出しは段の中の位置を保ち、テキストの代わりにデザインが描かれます。レベルのnumberingTemplateを刷る{number}を入れた円と、その右の{titleText}です(幅と詳細デザイン)。円とタイトルはどちらも高さ8.6 mmで、グリッドから外した見出しはちょうどその高さを確保するので、デザインにminHeightは要りません。番号はレベル2のカウンターから取るので、Markdownに活動を挿入すると、その後の活動の番号が振り直されます。自己評価の見出しはnumbered: falseのスタイルを使って番号の対象から外し、円の位置にSVGの星を置きます。
#4 · 表のセルに絵を入れる
const tableStyles = [{ id: 'match', borderRadius: mm(3), // no header row, so no header fill
headerBackgroundEnabled: false, bodyBackgroundEnabled: true, bodyBackground: col('paper'),
bodyFontFamily: LABEL, bodyFontSize: pt(13), bodyColor: col('ink'), cellPadding: mm(1.4),
rules: 'none' }]; // the white panel is the body fill alone
const cell = (content, extra) => ({ content, verticalAlign: 'middle', ...extra });
const dotCell = () => cell(':chip[ ]{style="dot"}', { align: 'center' });
const matchRow = (icon, food, part) => [cell('', { image: { resourceId: icon, width: 0.76 },
align: 'center' }), cell(food), dotCell(), cell(''), dotCell(),
cell(`:chip[${part}]{style="word"}`)];
const sheetType = { id: 'sheet', name: 'Worksheet item', shortLabel: '', captionPrefix: '',
numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal' }; // no caption, no number
// Set 'here' in its card, built once FOODS exist. A box keeps a line of its text, 6 mm, over
// an embedded table; with that off (see layout), a :::space{lines=0.33} sets ASK instead.
const foods = () => ({ id: 'foods', typeId: 'sheet', kind: 'table', createdAt: 0, updatedAt: 0,
placement: { position: 'here' }, table: { styleId: 'match', model: {
columnWidths: [0.14, 0.25, 0.06, 0.31, 0.06, 0.18], // the widest gap: room to draw a line
rows: FOODS.map((name, r) => matchRow(ICONS[r], name, PARTS[r])) } } });
TableCell.imageはリソースをセルの中に描きます。ここではセル幅の76 %で描き、行はそれに合わせて高くなります。verticalAlign: 'middle'で、食べ物の名前、点、チップを画像に対して中央にそろえます。表の31 %を占めるいちばん広い列は、児童が線を引くために空けておきます。名前付きのスタイルは表の枠の角を丸め、白い本文の塗りをその形で切り抜きます。罫は引かないので、パネルは白い塗りだけになります(名前付きの表スタイル)。リソースの種類のcaptionPrefixは空で、表にはキャプションのテキストもないので、表の下には何も刷られません。placement: { position: 'here' }は、表を::resourceの行がある位置、つまりカードの中に置きます。囲みはこうした表の上に自分の本文1行分、ここでは6 mmを空けます。layout.inlineResourceGapInBoxes: falseでそれを切り、::resourceの行の前の:::space{lines=0.33}で、解答欄が問いの下に取るのと同じ2 mmを空けます。
レシピの全体
// ═══ Postext Cookbook · Nº 022 · Worksheet with answer boxes and a word bank ══════
// https://postext.dev/en/cookbook/worksheet-answer-boxes
// Code: MIT · Text: original (CC BY 4.0) · Plant: diffusion models · Icons: drawn in code
// Fonts: Andika, Baloo 2, Fredoka (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'worksheet-answer-boxes';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#243040', muted: '#5d6975', paper: '#ffffff', // type; prompts; boxes
leaf: '#2f7d4a', sun: '#f4b43a', soil: '#8a5a36', // the accent; words to pick; drawings
tint: '#e5f1e7', rule: '#a9c9b1' }; // the activity cards; answer-box outlines
// Each colour names its palette entry and carries its hex.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at the leaf, so nothing prints blue.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.leaf })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, DISPLAY, LABEL] = ['Andika', 'Baloo 2', 'Fredoka']; // Andika: for early readers
const [TOP, SIDE] = [18, 16]; // mm; a sheet printed one-sided, so the margins do not mirror
// #region answer: cards that hold white answer boxes, stacked exactly, off the grid
// In the Markdown a box inside a box is a fence inside a fence (each ::: closes one):
// :::callout{type="card"}
// What is inside the pea pods?
// :::callout{type="answer"}
// Write here ← the prompt first: a :::space that opens a box is dropped
// :::space{lines=3} (gotcha: space-dropped-box-top)
// :::
// :::
const [ASK, AFTER, HEAD, NEXT] = [2, 5, 3, 9]; // mm: question→box, box→next, heading→card
const card = {
id: 'card', background: col('tint'), borderRadius: mm(4),
padding: { top: mm(4), right: mm(5), bottom: mm(5), left: mm(5) },
marginTop: mm(HEAD), marginBottom: mm(NEXT), // NEXT: under a card, to whatever follows
// Off the grid, or what follows a card drops to the next grid line. Only the outer card can
// set it: a nested box ignores snapToGrid, span and placement (gotcha: nested-callout-limits).
snapToGrid: false,
body: { paragraphSpacing: false }, // the boxes' margins do all the spacing
lists: { bulletChar: '', // no bullet: in the checklist a circle chip opens each item
gap: mm(2), itemSpacing: pt(7) }, columnGap: mm(6),
};
// A nested box's margins collapse with its neighbours', the larger winning (ASK, AFTER); the
// last box's marginBottom falls inside the card's padding instead of adding to it.
const nested = (id, look) => ({ id, background: col('paper'), borderRadius: mm(2.5),
marginTop: mm(ASK), marginBottom: mm(AFTER), ...look });
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
よくあるつまずき
つまずき
:::spaceは囲みや段の頭では捨てられる
:::spaceは、段の頭、:::columnsグループの頭、ほかに中身のあるタイトルなしの囲みの頭、分割された囲みの続きの頭では捨てられます。postext 1.5からは、:::spaceだけで作った囲みは空きが求めるとおりの高さになり(解答欄の囲み、書き込み用の場所)、囲みのタイトルのすぐ下に置いた空きは、その分だけ本文を下げて始めます。タイトルなしの囲みを空きで始めるには、タイトルか最初の行を与え、そのあとに空きを入れてください。 明示的な縦のアキ →
つまずき
入れ子の囲みはspan、placement、snapToGridを無視する
ほかの囲みの中に入れ子にした囲みは、自分のspan、placement、snapToGrid、floatBarrierを無視し、常に親の内側の幅で親の中を流れます。 入れ子の囲み →
つまずき
行送りより高いチップは次の行に触れる
箱が行送りより高いチップは、次の行のチップに触れます(chipOverlap警告)。上下のパディング、枠線、サイズを小さくするか、行送りを広げてください。 インラインのチップ →
Sandboxの検査 · chipOverlap
チップが隣の行に接触
原因. チップスタイルのチップが行送りより高いため、連続する行のチップどうしが接します。
対処. チップの上下の内側余白、輪郭線、サイズを小さくするか、行送りを大きくしてください。 ドキュメント →
- 囲みのスタイルに罫線入りの背景がないため、囲みが自分の中に記入用の罫線を引けません。解答欄は無地のまま
:::spaceで高さを取り、短い記入欄は枠線のチップで作ります。 numbered: falseの見出しスタイルも、そのレベルのデザインを描き、{number}が空のまま残ります。専用のデザインがなければ、自己評価は空の緑の円で始まってしまいます。そこでreviewは活動のデザインを複製し、円があった位置に星を置きます。
クレジット
- 本文
- 書き下ろしの文章, CC BY 4.0
- 画像
- The pea plant on the opener, a watercolour (top of the disc) · Generated With Diffusion Models · オリジナル
- The pea plant’s roots, the foot of the same watercolour below the band · Generated With Diffusion Models · オリジナル
- The plant's leader lines, the six food icons and the star, drawn in code in the page’s palette · Ignacio Ferro · MIT
- フォント
- Andika (SIL OFL 1.1) · Baloo 2 (SIL OFL 1.1) · Fredoka (SIL OFL 1.1)


