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

レシピ集 · 第12章 · 教科書

文章に合わせて囲みが伸びるワークブック

ページテンプレートで組む理科のワークブック。縦に積んだ囲みは文章に合わせて伸び、解答罫は空の枠に引き、収まらない工作は追加ページに続きます。

このページの内容

1ページ(全5ページ)

  • 英語の見本:日本語版はまだありません
  • 仕上がり210 × 280 mm
  • 1段
  • Andika 11.5/16
  • Baloo 2
  • Lexend
  • 5ページ
  • レベル
  • Postext 1.65.0
  • 組版時間84 ms
  • コード220行

かんたんな説明

水をテーマにした子ども向け理科ワークブックの5ページ。問題はそれぞれ色の付いた囲みに入り、下に答えを書く罫線があります。問題が長いと囲みが伸び、下のものを押し下げます。長い工作は次のページに続きます。

できあがり

架空の小学4年生向け理科ワークブック『Water on the move』の単元3から5ページを、210 × 280 mmで組みます。表紙は拡散モデルで生成した水の循環の画像が塗り足しまで広がり、下端で紙に溶け、その上に5本のベクターの矢印が重なり、その下に54 ptの書名と名前を書く罫線があります。プリントはどれも同じページテンプレートから組みます。単元名の行、青い帯の見出し、小さな画像を添えた短い本文、番号のタブが付いた水色の活動の囲みが三つ。一つめと三つめの囲みの下には答えを書く罫線があります。囲みの高さは中の文章で決まるので、あちこちで1行ずつ長くなるフランス語版では、テンプレートの位置を何も変えなくても英語版より罫線が下に来ます。工作はペットボトルで雨量計を作るもので、手順が1ページに収まりません。手順の囲みはページの下端で Continued を付けて切れ、追加されたページの上で続き、そのあとに観察を書く6本の罫線が続きます。タブや観察欄の見出しを含め、文字はすべてMarkdownに書きます。

このレシピが答える質問

  • ページの囲みを文章に合わせて伸ばし、下の囲みを押し下げるには?
  • 収まらない活動を「次ページへ続く」の印を付けて次のページに続けるには?
  • 記入線、解答欄、語群、チェックリストのあるワークシートのページを作るには?

手短な答え

script.js · 49〜75行コード全体で見る
// An empty frame is an answer space: the Markdown sends it nothing (optional: no slotEmpty).
// Its `rules` draw a line at the foot of every LINE mm of its height, so the lines are part
// of the frame and move with it when a box above grows. minHeight too: a box that runs out of
// room may not take the lines away from the child.
const answer = (name, lines) => ({ name, optional: true, width: mm(W), height: mm(LINE * lines),
  minHeight: mm(LINE * lines),
  rules: { every: mm(LINE), color: col('rule'), width: pt(0.75) } });
// A box is as tall as its text, never less than drawn: a longer text makes it taller and
// pushes everything after it in the group down the page.
const box = (name, style, minHeight) => ({ name, style, width: mm(W), minHeight: mm(minHeight) });
const sheet = {
  id: 'ficha',
  decoration: { elements: [kicker] },
  frames: [
    ...opening,
    // The group starts where its first box is placed: under the text, and runs down from there.
    { ...box('act-1', 'actividad', 22), placement: at('#texto', 'below', 0, 6) },
    answer('lineas-1', 3),
    box('act-2', 'actividad', 22),
    // The last box goes on overleaf, with the answer space after it, when its text outgrows
    // the page; the other two push it down instead.
    { ...box('act-3', 'actividad', 22), overflow: { continueIn: 'next-page' } },
    answer('lineas-3', 2),
  ],
  groups: [{ name: 'actividades', kind: 'stack', gap: mm(4.5),
    frames: ['act-1', 'lineas-1', 'act-2', 'act-3', 'lineas-3'] }],
};

材料

種類
Andika, Baloo 2, Lexend (SIL OFL 1.1)
素材
  • estados-960.jpg
  • planeta-960.jpg
  • pluviometro-960.jpg
  • portada-1440.jpg
  • The water cycle in a landscape: snowy mountains, a river, a coast and the sea, under sun and rain clouds. (Generated With Diffusion Models, オリジナル)
  • The Earth seen from space, with a drop of water. (Generated With Diffusion Models, オリジナル)
  • An ice cube melting, a glass of water and a steaming cup. (Generated With Diffusion Models, オリジナル)
  • A rain gauge made from a cut bottle, with a ruler and stones. (Generated With Diffusion Models, オリジナル)

作り方

#1 · 活動を名前で自分の囲みに流し込む

テンプレートは上の手短な答えです。Markdownでは、プリント1枚が1つの::::pageブロックです。最初の見出しはtakes: 'h1'の枠へ、段落は流し込み枠へ、:::frame{slot="…"}はそれぞれ同じ名前の枠へ入り、タブの文字はlabelに書きます。解答の枠には何も入らないのでoptional: trueを付けます。付けないと空の枠がslotEmptyの警告を出します。絵を描く活動は:::space{lines=3}で自分の囲みの中に白い場所を取ります。どれだけの場所が要るかは、問題の一部だからです。

:::frame{slot="act-1" label="1 · Read and answer"}
Tom lives in Leeds. The water from his tap comes from a reservoir in the hills…
:::

#2 · 罫線を囲みと一緒にスタックで動かす

囲みにはどれも描いたときの高さ22 mmをminHeightに指定し、それより上はautoの高さにします。グループは、本文の下に置いたact-1の位置から5つの枠を4.5 mm間隔で縦に並べるので、ある囲みが伸びるとその後ろがすべて下がります。罫線は空の枠そのものに属します。そのrulesが、枠の高さ8 mmごとの下端、文字の下に1本ずつ線を引くので、罫線は枠と一緒に動き、解答欄を長くすれば枠が高くなります。解答の枠には高さと同じminHeightを指定してください。グループの場所が足りなくなると、リフローの段階はグループの枠から最小値まで場所を取り戻しますが、空の枠の最小値はゼロなので、罫線が次の囲みに重なってしまいます。ワークシートの最後の囲みact-3は、文章がページに収まらないと次のページへ続き(overflow.continueIn: 'next-page')、その下の解答の罫線も一緒に移ります。

#3 · 工作を次のページへ続ける

script.js · 79〜106行コード全体で見る
const project = {
  id: 'proyecto',
  overflowTemplate: 'proyecto-sigue',
  decoration: { elements: [kicker] },
  frames: [
    ...opening,
    { ...box('material', 'material', 20), placement: at('#texto', 'below', 0, 9) },
    // As tall as its text, never past the foot of the page, at full size: the rest ends
    // with the language's mark (Continúa, Continued, À suivre) and goes on on an added page.
    { name: 'pasos', style: 'proyecto', width: mm(W), overflow: { continueIn: 'next-page' } },
  ],
  groups: [{ name: 'trabajo', kind: 'stack', gap: mm(9), frames: ['material', 'pasos'] }],
};
// The added page: the rest of the steps at the head, then lines for the child's notes,
// under a heading the page fence names (notas="…").
const projectGoesOn = {
  id: 'proyecto-sigue',
  decoration: { elements: [kicker,
    { kind: 'text', id: 'notas-titulo', content: '{attr.notas}', fontFamily: DISPLAY,
      fontSize: pt(15), fontWeight: 700, color: col('sea'),
      placement: { ...at('#notas', 'top-left', 0, -3), size: { width: mm(W) } } }] },
  frames: [
    { name: 'pasos', style: 'proyecto', width: mm(W),
      placement: at('container', 'top-left', 0, 9) },
    answer('notas', 6),
  ],
  groups: [{ name: 'trabajo', kind: 'stack', gap: mm(16), frames: ['pasos', 'notas'] }],
};

手順の囲みには決まった高さがなく、文章に合わせて伸び、版面の下端で止まります。別のページへ続けられる枠は、文字を縮める前に続きへ送ります。そのため囲みは本来の文字サイズのまま行と行のあいだで切れ、言語ごとの継続マーカー(localeに応じて Continúa、Continued、À suivre)で終わり、proyecto-sigueのページの同じ名前の枠で続きます(文章が追加ページに続くとき)。追加されたページは囲みの続きの下に観察の罫線を引き、見出しにはページブロックに書いたnotas="What I noticed"の文字を使います。文字はMarkdownに残り、版ごとに変わります。

#4 · 表紙を裁ち落としまで描く

script.js · 110〜131行コード全体で見る
// and a line for the child's name
const cover = {
  id: 'portada', header: false, footer: false,
  decoration: { elements: [
    { kind: 'image', id: 'cielo', resourceId: 'portada', decorative: true,
      placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: mm(178) } } },
    // The arrows are vector, over the painting: the same frame, so they stay on its features.
    { kind: 'image', id: 'ciclo', resourceId: 'ciclo', decorative: true,
      placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: mm(178) } } },
    { kind: 'rule', id: 'nombre-linea', direction: 'horizontal', thickness: pt(1),
      color: col('sea'), placement: { ...at('#nombre', 'bottom-left', 0, 1),
        size: { width: mm(W) } } },
  ] },
  frames: [
    { name: 'titulo', takes: 'h1', width: mm(W), placement: at('container', 'top-left', 0, 162) },
    { name: 'subtitulo', flow: true, width: mm(W) },
    { name: 'nombre', style: 'campo', width: mm(W), minHeight: mm(12) },
    { name: 'colofon', style: 'colofon', width: mm(W), placement: at('container', 'bottom-left') },
  ],
  groups: [{ name: 'portada', kind: 'stack', gap: mm(4),
    frames: ['titulo', 'subtitulo', 'nombre'] }],
};

表紙もテンプレートページです。画像は塗り足しに固定した装飾で、書名、シリーズ名、名前欄が版面の上から162 mmの位置から始まる縦の積み重ねになります。名前の罫は枠の下端に固定してあるので、別の言語でラベルが2行になっても罫は文字の下にあります。header: falseとfooter: falseで表紙にはノンブルを付けません。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 159 · Activity book with boxes that grow ══════════════
// https://postext.dev/en/cookbook/activity-book-growing-boxes
// Code: MIT · Text: original (CC BY 4.0) · Pictures: generated with diffusion models
// Fonts: Andika, Baloo 2, Lexend (SIL OFL 1.1) · Needs postext ≥ 1.65.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es' | 'fr')
const RECIPE = 'activity-book-growing-boxes';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one ink, the water blue, the sun, and the pale fields of the boxes
const palette = {
  ink: '#1f2d38', // text
  sea: '#1d659c', // titles, tabs, list numbers
  sky: '#e2f0f9', // activity boxes
  sun: '#f0a531', // the project's box
  sand: '#fcf0d8', // the materials box
  rule: '#93bcd8', // answer lines, blanks
  paper: '#ffffff',
};
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' } })),
  { id: 'main-color', name: 'sea (defaults)', value: { hex: palette.sea, model: 'hex' } },
];
// #endregion

const [TEXT, DISPLAY, LABEL] = ['Andika', 'Baloo 2', 'Lexend']; // Andika: for early readers
const W = 174; // mm: the width of the type area, and of every box
const LINE = 8; // mm between two answer lines: room for a child's handwriting
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });

// The head every sheet shares: the unit over the title band, the text with its drawing.
const kicker = { kind: 'text', id: 'tema', content: '{attr.tema}', fontFamily: LABEL,
  fontSize: pt(8.5), fontWeight: 600, color: col('sea'), textTransform: 'uppercase',
  letterSpacing: pt(1.4), placement: at('container', 'top-left') };
const opening = [
  { name: 'titulo', takes: 'h1', style: 'banda', width: mm(W),
    placement: at('container', 'top-left', 0, 6) },
  { name: 'texto', flow: true, width: mm(W - 52), minHeight: mm(36),
    placement: at('#titulo', 'below', 0, 4) },
  { name: 'dibujo', width: mm(44), placement: at('#titulo', 'below', W - 44, 4) },
];

// #region answer: boxes in a stack grow with their text; empty ruled frames hold the answers

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

アレンジ

#活動の罫線を増やす

罫線の本数は解答の枠の高さで決まります。rulesが入るだけの線を引くので、テンプレートでこの値を変えれば、それを使うすべてのワークシートにその本数の罫線が付きます。

-    answer('lineas-1', 3),
+    answer('lineas-1', 5),

#続ける前に手順を縮めてみる

別のページへ続けられる枠は、文字を縮める前に続きへ送ります。fit.preferContinue: falseを指定すると、段階はまず手順をfit.minScale(90 %)まで小さく組み、それでも足りないときだけ別のページへ送ります。子どもの本では、1ページ減らすことより文字の大きさのほうが大事なので、このレシピは既定のままにしています。

-      overflow: { continueIn: 'next-page' } },
+      fit: { preferContinue: false }, overflow: { continueIn: 'next-page' } },

よくあるつまずき

  • 何も入らない枠は、optional: trueを付けないとslotEmptyを出します。ここでは解答の枠すべてに付けています。
  • 積み重ねでは囲みを置くのはグループで、囲み自身のplacementは使われません。ただし最初の一つは例外です。グループの最初の囲みの位置を決めておかないと、積み重ねは版面の上端から始まり、見出しに重なります。

クレジット

レシピ
Ignacio Ferro
本文
書き下ろしの文章, CC BY 4.0
画像
  • The water cycle in a landscape: snowy mountains, a river, a coast and the sea, under sun and rain clouds. · Generated With Diffusion Models · オリジナル
  • The Earth seen from space, with a drop of water. · Generated With Diffusion Models · オリジナル
  • An ice cube melting, a glass of water and a steaming cup. · Generated With Diffusion Models · オリジナル
  • A rain gauge made from a cut bottle, with a ruler and stones. · Generated With Diffusion Models · オリジナル
フォント
Andika (SIL OFL 1.1) · Baloo 2 (SIL OFL 1.1) · Lexend (SIL OFL 1.1)
SandboxPDF