かんたんな説明
日時計を作る学校の理科ワークシートです。2つの段にまたがって分かれる囲み、次のページの上に移る囲み、ページの下に固定される囲みを示します。
できあがり
スペインの学校向け理科実習教材『Taller de ciencias』の4ページ、「Práctica 4」の「Construye un reloj de sol」(日時計を作る)です。42ページでは安全上の注意をひとかたまりのまま保ちます。14手順の作業手順は黄色の地にコンパスのバッジを角に付け、左の段の下端から始まって右の段の頭に続きます。続きの部分は同じ行長で、題はありません。マドリードのデータシートはそのページで本文の流れを離れ、43ページの頭に本文より上に置かれます。最後のページの地には、チャコールの「Autoevaluación · 10 min」のバッジを固定し、その横の余白に指さしの手を添えます。扉では、太陽のような黄色の帯に、マドリードの緯度で正午から午後5時までの棒の影を描いた図を載せ、材料の一覧をページ幅いっぱいの3段のパネルに並べます。
このレシピが答える質問
- 長い囲みを段やページをまたいで分割させたり、短い囲みを分割させないようにしたりするには?
- 本文を流したまま、囲みをページの上端や下端にフロートとして配置するには?
- バッジやステッカーをページ上の決まった位置に固定するには?
- ページの途中に、2段をまたぐ囲み(3つ並びの「数字で見る」欄など)を置くには?
手短な答え
const HAND = 6, GAP = 2, RULE = 0.75 * PT; // mm: the badge's hand, its gap, the hand's rule
const calloutStyles = [
// Kept whole: keepTogether defaults to true, so a box that does not fit the rest of a
// column moves on in one piece; only a box taller than a whole column splits anyway.
box('seguridad', bar('charcoal', 'aviso')),
// Split: the procedure fits a column, so it takes keepTogether: false to break where it
// falls instead of moving on whole: between steps, or inside one (splitMinLines, default
// 2, keeps at least two lines of the step on each side of the cut). The rest goes on in
// the next column or page without the title or the icon; a corner icon takes no room
// from the text, where an inline one would keep its column in both parts.
box('pasos', { keepTogether: false, background: col('light'),
icon: icon('compas', 7, { position: 'corner', cornerSide: 'outer' }) }),
// Floated: its fence adds placement="top", so the box leaves the flow where the fence
// stands and heads the next page, while the text after it fills this one.
box('datos', { span: 'page', background: col('tint') }),
// Pinned: 'fixed' sets the box on the page where its fence falls, at the bottom-left corner
// of the text block unless fixed.anchor says otherwise, and the column text keeps out of it.
// width: 'auto' shrink-wraps the title, so an empty fence prints a badge.
box('autoevaluacion', { placement: 'fixed', width: 'auto',
// Hang the hand and its rule in the margin (the outer one on this verso), so the badge
// itself lines up with the text: [hand][rule][GAP][badge].
fixed: { offset: { x: mm(-(HAND + RULE + GAP)) } },
marker: { ...icon('mano', HAND), gap: mm(GAP),
rule: { enabled: true, color: col('charcoal'), width: mm(RULE) } },
background: col('charcoal'), borderRadius: mm(3.2),
padding: { top: mm(1.6), right: mm(3.4), bottom: mm(1.6), left: mm(3.4) },
titleStyle: { ...TITLE, color: col('paper') } }),
// Across the page, in the flow: the text above it is cut level and resumes under it.
box('resumen', { span: 'page', backgroundEnabled: false,
stripe: { enabled: true, side: 'top', width: pt(2.5), color: col('charcoal') } }),
];
材料
- 機能
- 分割する囲み、分割しない囲みフロートする囲み固定位置の囲みとバッジ囲みの横のマーカー段段抜きの囲み囲みの中や本文中の段組み囲みのアイコンと角のバッジ囲み明示的な縦のアキ図を配置する参照図の配置段末そろえデータから作る表名前付きの表スタイル「図」と「表」を文書の言語で番号付き見出しデザインした章扉見出しの属性柱とノンブル警告と診断
- 種類
- Host Grotesk, Commit Mono (SIL OFL 1.1)
- 素材
- The shadow chart, the dial in profile and the icons, drawn in code in the page's palette (Ignacio Ferro, CC BY 4.0)
作り方
#1 · すべての囲みに共通の基本スタイル
const TITLE = { fontFamily: LABEL, fontSize: pt(8), color: col('charcoal'),
textTransform: 'uppercase', letterSpacing: pt(1.2) }; // bold by default
const BOX_TYPE = { fontSize: pt(8.8), lineHeight: pt(12.4) }; // colours inherit bodyText
const box = (id, device) => ({ id, // margins: the defaults, snapped to whole grid lines
padding: { top: mm(3), right: mm(3.6), bottom: mm(3.4), left: mm(3.6) },
titleStyle: { ...TITLE, gap: mm(2) }, body: BOX_TYPE,
lists: { gap: mm(2), itemSpacing: pt(3) }, ...device });
const icon = (id, size, extra) => ({ kind: 'resource', resourceId: id, size: mm(size),
...extra });
// A side bar with its icon centred on it, 1.4 mm narrower than the bar.
const bar = (hue, id, width = 5.6) => ({ backgroundEnabled: false,
stripe: { enabled: true, side: 'left', width: mm(width), color: col(hue) },
icon: icon(id, width - 1.4) });
どのスタイルもbox()から始まります。等幅書体の題、本文の9.4ptに対して8.8ptの文字、そして内側余白です。そこに、それぞれ1つずつ目印を加えます。安全上の注意にはチャコールの帯、作業手順には黄色の地、データシートには紙色に近い淡い色、まとめには上罫、バッジにはチャコールの角丸の形です。生徒は題を読む前に、その目印で囲みを見分けられます。作業手順では、地の色が続きの目印にもなります。右の段の頭にある部分には題がないので、左の段の下端にある手順1から4とつなげているのは黄色だけです。
#2 · 保つ、分ける、フロートさせる、固定する
コードは前に掲げた手短な答えです。作業手順の高さは192mmで、1段には211mm入ります。ひとかたまりに保つと囲みは右の段の頭へ跳び、左の段の下端に43mmの空きが残ります。keepTogether: falseを指定すると、囲みは落ちた位置から始まり、次の段、あるいは2つ目のアレンジで示すように次のページへ続きます(:::calloutコンテナー)。続きの部分では題とアイコンが省かれます。インラインのアイコンは、前後どちらの部分でも手順から専用の列を取ります。そこでコンパスは囲みの外側の角に置き、幅を取らせないようにしています。データシートの囲みの記述にはplacement="top"があるので、囲みは42ページで本文の流れを離れ、次のページの頭に置かれます。バッジはfixedで、負のoffset.xが指さしの手とその罫を外側の余白へ移すので、バッジの左端は本文にそろいます。
#3 · 3段のパネルでページを横切る
const materials = box('material', { span: 'page', background: col('sun'),
marginBottom: pt(LEAD), // one more grid line of air before the text resumes
padding: { top: mm(3.6), right: mm(4.4), bottom: mm(3.8), left: mm(4.4) },
columnGap: mm(GUTTER), // the page's gutter: the panel's columns sit as far apart as the text's
body: { ...BOX_TYPE, paragraphSpacing: false },
lists: { color: col('ink'), gap: mm(1.8), itemSpacing: pt(1) } });
span: 'page'を指定すると、材料の囲みは両方の段にまたがります。その上の導入文は高さをそろえて切られ、本文はパネルの下で2段組みに戻ります(41ページ)。囲みの中では、:::columns{count=3 breaks="5,9"}が、段をそろえるのではなく各段の始まる位置を決めます。breaksは子ブロックを数え、リストの項目は1つで1ブロックなので、2段目と3段目は5番目と9番目のブロック、つまり太字のラベルから始まります。columnGapはページの段間と同じ7mmなので、パネルの段の間隔は本文の段と同じです。
:::callout{type="material" title="Necesitarás"}
:::columns{count=3 breaks="5,9"}
**Para la esfera**
- Cartón pluma de 20 × 30 cm
- La plantilla de la esfera
- Pegamento y rotulador
**Para el gnomon y la base**
…
:::
:::#4 · 面には黄色を、長い囲みには明るい黄色を
const palette = {
ink: '#1b2430', // text
charcoal: '#2b2d42', // the safety bar, the summary's rule, the table head, the badge, titles
sun: '#f2b705', // the opener band and the materials panel: fields, never type
light: '#fad65a', // the procedure
tint: '#fff6d6', // the data sheet
rule: '#d7dde3', // hairlines
muted: '#5d6b78', // running heads, notes
paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at charcoal, so nothing prints blue.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.charcoal })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
太陽の黄色は色の面、つまり帯とパネルにだけ使います。そこではチャコールと墨色の文字がそれぞれ7.4:1と8.6:1で読めます。白地の文字色にすると1.8:1にしかならないので、文字には使いません。作業手順には淡い黄色のlightを使います。墨色の文字は11:1で読め、ギャラリーのサムネイルでも分かれ目が見えます。データシートには紙色に近いtintを使い、見開きでもう1つの地色付きの囲みである作業手順と見間違えないようにします。main-colorはチャコールを指すので、設定で上書きしていない既定の要素はエンジンの青ではなくチャコールで印刷されます。
#5 · 黄色の帯で扉を開く
const BAND = 100; // mm from the trim to the foot of the band
const ART_W = 80; // mm: the width of the band's drawing, at the fore-edge
const AIR = 8; // mm between the band and the first line of text
const [TITLE_W, LEAD_W] = [104, 88]; // mm: the title's and the lead's measure
const onBand = { color: col('charcoal'), align: 'left' }; // a long title or lead wraps
const below = (id, y, width) => ({ anchor: { to: `#${id}`, edge: 'below' },
offset: { y: mm(y) }, size: { width: mm(width) } });
const opener = { enabled: true, minHeight: mm(BAND - TOP + AIR), slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('sun') },
placement: { anchor: { to: 'page', edge: 'top-left' }, size: { height: mm(BAND) } } },
{ kind: 'image', id: 'art', resourceId: 'sombras', placement: { anchor: { to: 'page',
edge: 'top-right' }, size: { width: mm(ART_W), height: mm(BAND) } } },
{ kind: 'text', id: 'kicker', content: '{attr.kicker}', ...onBand, fontFamily: LABEL,
fontSize: pt(8.5), fontWeight: 700, letterSpacing: pt(1.7), textTransform: 'uppercase',
placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(4) } } },
{ kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: TEXT,
fontSize: pt(44), fontWeight: 800, lineHeight: 0.98, placement: below('kicker', 3, TITLE_W) },
{ kind: 'text', id: 'lead', content: '{attr.lead}', ...onBand, fontFamily: TEXT,
fontSize: pt(10.5), lineHeight: 1.4, placement: below('title', 5, LEAD_W) },
{ kind: 'text', id: 'meta', content: '{attr.meta}', ...onBand, fontFamily: LABEL,
fontSize: pt(7.4), fontWeight: 700, letterSpacing: pt(1.1), textTransform: 'uppercase',
placement: below('lead', 4, LEAD_W) },
] } };
帯はページに固定した箱要素で、図は小口側の画像要素です。見出し前置き、リード文、授業の行は見出し行の属性から作られます。帯がページに固定されているので、扉はすでに帯の下端までの高さを確保しており、本文はその3.6mm下から始まるはずです。minHeight: BAND - TOP + AIRは8mmを求めます。確保した高さは次のグリッド線にスナップするので、本文は帯の8.4mm下から始まります。
レシピの全体
// ═══ Postext Cookbook · Nº 021 · Boxes that split, float and pin ══════════════════
// https://postext.dev/en/cookbook/boxes-split-float-pin
// Code: MIT · Text: original (CC BY 4.0) · Drawings: generated in code (CC BY 4.0)
// Fonts: Host Grotesk, Commit Mono (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// Four pages of a school lab workbook in Spanish, and five ways a box can sit on them.
import {
buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'es'; // @lang: the language of the sample document (this recipe is Spanish only)
const RECIPE = 'boxes-split-float-pin';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one yellow for fields, paler ones for two boxes, near-blacks for type and bars
const palette = {
ink: '#1b2430', // text
charcoal: '#2b2d42', // the safety bar, the summary's rule, the table head, the badge, titles
sun: '#f2b705', // the opener band and the materials panel: fields, never type
light: '#fad65a', // the procedure
tint: '#fff6d6', // the data sheet
rule: '#d7dde3', // hairlines
muted: '#5d6b78', // running heads, notes
paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color': point it at charcoal, so nothing prints blue.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.charcoal })
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const TEXT = 'Host Grotesk'; // text and display
const LABEL = 'Commit Mono'; // labels: kickers, box titles, step numbers, heads, the table
const LEAD = 13.6; // pt: the body leading, the pitch of the baseline grid
const LINES = 44; // grid lines in a full column
const [TRIM_W, TRIM_H, TOP, INNER, OUTER, GUTTER] = [195, 255, 22, 18, 14, 7]; // mm
const PT = 25.4 / 72; // mm in a point
// #region look: the base of every box (a mono title, smaller type), then one device each
const TITLE = { fontFamily: LABEL, fontSize: pt(8), color: col('charcoal'),
textTransform: 'uppercase', letterSpacing: pt(1.2) }; // bold by default
const BOX_TYPE = { fontSize: pt(8.8), lineHeight: pt(12.4) }; // colours inherit bodyText
const box = (id, device) => ({ id, // margins: the defaults, snapped to whole grid lines
padding: { top: mm(3), right: mm(3.6), bottom: mm(3.4), left: mm(3.6) },
titleStyle: { ...TITLE, gap: mm(2) }, body: BOX_TYPE,
lists: { gap: mm(2), itemSpacing: pt(3) }, ...device });
const icon = (id, size, extra) => ({ kind: 'resource', resourceId: id, size: mm(size),
...extra });
// A side bar with its icon centred on it, 1.4 mm narrower than the bar.
const bar = (hue, id, width = 5.6) => ({ backgroundEnabled: false,
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#作業手順をひとかたまりに保つ
この設定をなくすと、1段に収まる作業手順はそのまま右の段の頭へ移り、左の段の下端に43mmの空きが残ります。
- box('pasos', { keepTogether: false, background: col('light'),
+ box('pasos', { background: col('light'),#データシートを地へフロートさせる
content.es.mdでplacement="bottom"にすると、データシートは記述のある42ページの下端に入ります。押し出された作業手順は右の段の頭から始まり、ページをまたいで分かれ、43ページの頭で終わります。
-:::callout{type="datos" placement="top" title="Hoja de datos · Madrid, 40,4° N · 3,7° O"}
+:::callout{type="datos" placement="bottom" title="Hoja de datos · Madrid, 40,4° N · 3,7° O"}よくあるつまずき
つまずき
'top'のフロートは参照ページの先頭を許さない限り次のページに置かれる
既定では、フロートが自分の参照より上に置かれることはありません。そのため、Nページで参照したページ幅の'top'フロートはN+1ページの頭に置かれます。リソースまたはその種類のdefaultPlacementにplacement.citingPage: trueを設定すると(本全体ならlayout.floatsAtCitingPage、postext 1.25から)、layout.maxTopFraction以内に収まり参照行がそのページに残る場合は代わりにNページの先頭に置かれ、参照より前の本文はその下に送られます。章の最初のページと強制改ページの後のページの先頭には置かれません。その場合は次のページに置かれ、'auto'または'bottom'なら参照したページの下端に入れられます。 図の配置 →
つまずき
1ページは奇数ページ。ページは物理的な番号で計画する
1ページは右ページで、2ページが最初の偶数ページです。見開きは物理的なページ番号で計画してください。偶数ページの章扉は、その次の奇数ページと向かい合います。 改ページと改段 →
レイアウト警告 · calloutOverflow
段からはみ出す囲み
原因. どこでも分割できない囲み(段より高い図、表、入れ子の囲み、または大きすぎるsplitMinLines)が、はみ出した状態で配置されました。エンジンはこれをdoc.warningsに記録し、Sandboxが一覧に表示します。空のサイド段より高いspan: 'side'の囲みも、はみ出した状態で配置されます。
対処. 囲みを短くする、keepTogether: falseで分割を許す、splitMinLinesを下げる、または別のスパンを指定してください。 ドキュメント →
- 1段より高い囲みは、
keepTogetherの値にかかわらず分割されます。この設定が効くのは、211mmの段に入る192mmのこの作業手順のように、1段に収まる囲みだけです。 splitMinLines(既定は2)は、切れ目の前後それぞれに残す最少の行数で、切られる手順の行で数えます。そのため、手順の1行だけが切り離されることはありません。この作業手順の前の本文は、切れ目が手順4と5の間に来るように調整してあります。分割される囲みより前の本文を直すと切れ目が動くことがあるので、直すたびに切れ目の位置を確かめてください。- インラインのアイコンは専用の列を取り、続きの部分もその列を空のまま保ちます。手順は前後どちらの部分でもアイコンの幅だけ狭くなります。角に置いたアイコンか、アイコンを載せる側面の帯を使えば、手順は行長いっぱいに組めます。
placement="top"でフロートさせた囲みは、記述のあるページの次のページの頭に置かれます。そのため記述は、囲みを置きたいページの1つ前のページに書きます。ここでは42ページの作業手順の直前にあります。
クレジット
- 本文
- The solar-noon table: computed for Madrid with NOAA's solar equations · NOAA Global Monitoring Laboratory · パブリックドメイン
- 画像
- The shadow chart, the dial in profile and the icons, drawn in code in the page's palette · Ignacio Ferro · CC BY 4.0
- フォント
- Host Grotesk (SIL OFL 1.1) · Commit Mono (SIL OFL 1.1)


