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

レシピ集 · 第1章 · ページとグリッド

地域の会報:トップ記事と短信

1段半組みで2ページの市民農園の会報。トップ記事は広い段を埋めて2ページ目へ続き、段区切りでタグ付きの短信を狭い段へ送ります。

このページの内容
出力
Canvas
レベル
中級
Postext
Postext 1.65.0で検証済み
1.25.0以上が必要
ライセンス
2026年10月11日更新
コードMIT · 本文CC BY 4.0

1ページ(全2ページ)

  • 英語の見本:日本語版はまだありません
  • 仕上がり210 × 297 mm
  • 1段半組み, 段間8 mm
  • Work Sans 9.4/13.4
  • Courier Prime
  • Titan One
  • 2ページ
  • レベル
  • Postext 1.57.1
  • 組版時間55 ms
  • コード168行

かんたんな説明

家庭菜園の会が出す2ページの会報です。メインの記事は広い段に入って2ページ目へ続き、短いお知らせはその横の狭い段に並びます。

できあがり

架空の市民農園の会が出す会報『The Allotment Gazette』の春号です。A4判1枚の両面に刷ります。麦わら色の帯には、Titan Oneで2行に組んだ題字、下端に一列の苗、号数と季節を入れたトマト色のタブを置きます。その下でページは113 mmの段と57 mmの段に分かれます。新しい3つの堆肥置き場を伝えるトップ記事は、コードで描いた敷地の配置図の下で広い段を埋め、「Continued on page 2」のタグで止まります。狭い段には5本の短信が入り、それぞれピル型のタグで始まります。2ページ目では送りの見出しの下で記事が再開し、温度のグラフを段の中央に置きます。さらに下では、苗床の説明の段落が、段の右に置いたその画像の横に組まれます。狭い段は8件のお知らせで埋まります。

このレシピが答える質問

  • 幅の広い本文の段と幅の狭いサイド段からなる1段半のレイアウトにするには?
  • Postextは3段以上の段組みや、画像の周りへの回り込みに対応していますか?
  • 囲みの中を2段にするには(本文の段と図の段を並べる)?
  • キーボードのキー、タグ、練習問題の語群などのインラインのチップを作るには?

手短な答え

script.js · 33〜49行コード全体で見る
const layout = {
  layoutType: 'oneAndHalf', // the narrow column sits on the right and takes text (the
  // defaults of sideColumnSide and sideColumnRole; 'floats' would keep text out of it)
  sideColumnPercent: 32, // 57 mm of the 178 mm measure
  gutterWidth: mm(8), // the wide column keeps the other 113 mm
  columnRule: { enabled: true, color: col('rule') }, // a 0.5 pt hairline in the gutter
};
// The text runs down the wide column, then the narrow one, then the next page's wide
// column. A :::columnbreak sends the next block on to the following column, so the
// Markdown decides what each column holds:
//   ## Shared compost bays open by the top gate      ← the lead, in the wide column
//   … :chip[Continued on page 2]{style="jump"}
//   :::columnbreak                                    ← the briefs open the narrow column
//   ## In brief {style="rail"}
//   …
//   :::columnbreak                                    ← from the last column: next page
//   :chip[Continued from page 1]{style="jump"}        ← the lead goes on in the wide column

材料

種類
Work Sans, Titan One, Courier Prime (SIL OFL 1.1)
素材
  • The site plan, the temperature chart, the square-metre bed and the row of seedlings under the nameplate, drawn in code in the page's palette (Ignacio Ferro, CC BY 4.0)

作り方

#1 · Markdownで各段を埋める

レイアウトの設定は前の手短な答えにあります。oneAndHalfレイアウトでは狭い段も初期設定で本文を受け、本文は広い段、狭い段、次のページの広い段の順に流れます(レイアウトの種類)。:::columnbreakはその位置で段を終えます(ディレクティブ)。トップ記事の「Continued on page 2」タグのあとでは短信のために狭い段を開き、最後の短信のあと、つまりページの最後の段では2ページ目を開きます。この号では1ページ目の両方の段が、上端から275 mmの同じグリッド線で終わるように調整してあるため、どちらの区切りを消してもページは変わりません。区切りが効いてくるのは原稿が変わったときです。トップ記事の第2段落を削ると、最初の区切りがない場合、「In brief」は広い段の上から247 mm、タグの下で始まります。最初の短信は狭い段へはみ出し、その後半は段の57 mmの行長で組み直されます。

#2 · フロントマターから題字を組む

script.js · 53〜75行コード全体で見る
const BEARING = 0.6; // mm: Titan One's left side bearing at 60 pt (T 0.42, G 0.63, L/H 0.85)
const DRILL = { id: 'drill', typeId: 'drawing', kind: 'svg', createdAt: 0, updatedAt: 0,
  svg: { fileId: 'drill.svg', width: 2100, height: 80 } }; // drawn by the design, not the text
const masthead = { enabled: true,
  minHeight: pt(10 * LEAD), // ten grid lines: the text starts one line clear of the band
  slot: { elements: [
    // The band is 62 mm deep. The column rule starts under the masthead, where the text does.
    { kind: 'box', id: 'band', style: { backgroundColor: col('straw') },
      placement: { ...at('page', 'top-left'), size: { width: mm(210), height: mm(62) } } },
    { kind: 'image', id: 'drill', resourceId: 'drill', // seedlings along the band's foot
      placement: { ...at('page', 'top-left', 0, 54), size: { width: mm(210), height: mm(8) } } },
    { kind: 'text', id: 'society', content: '{subtitle}', ...caps(8, 'leaf'), align: 'left',
      placement: { ...at('page', 'top-left', SIDE, 12), size: { width: mm(150) } } },
    { kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY, fontSize: pt(60),
      lineHeight: 0.9, // 54 pt from line to line
      color: col('leaf'), align: 'left', overflow: 'wrap', // two lines in 178 mm
      placement: { ...at('page', 'top-left', SIDE - BEARING, 17), size: { width: mm(178) } } },
    // {attr.issue} comes from the H1 line, {publishDate} from the frontmatter.
    { kind: 'text', id: 'tab', content: '{attr.issue} · {publishDate}', ...caps(9, 'paper'),
      align: 'right', box: { backgroundColor: col('tomato'),
        padding: { top: mm(1.8), right: mm(3.2), bottom: mm(1.6), left: mm(3.2) } },
      placement: at('page', 'top-right', -SIDE, 44) },
  ] } };

H1には題字を描くデザインのある見出しスタイルを当て、span: 'page'でそのデザインを両方の段の上に置きます。60 ptの{titleText}は幅178 mmのボックスの中で2行に折り返します。タブは、H1の行に書いた{attr.issue}と、フロントマターの{publishDate}をつなげたものです(テキスト要素)。minHeightがないと、題字は上端から62 mmの帯の下端までしか場所を取らず、本文は次のグリッド線、62.5 mmから始まって帯に接してしまいます。グリッド線10本ぶんのminHeightを指定すると、本文は67 mmから始まります。

#3 · チップで短信にタグを付ける

script.js · 79〜89行コード全体で見る
const chip = (id, look) => ({ id, fontFamily: LABEL, bold: true,
  fontSize: pt(7.7), // in points: em(0.82) is 7.7 pt in the text, 6.6 pt on the 8 pt jump lines
  borderWidth: pt(0), borderRadius: em(1), // a radius past half the height draws a pill
  paddingX: em(0.5), paddingY: em(0.14), ...look }); // em: of the chip's own size
const chipStyles = [
  chip('tag', { background: col('tomato'), color: col('paper') }), // the first is the default
  chip('free', { background: col('marigold'), color: col('ink') }),
  chip('when', { backgroundEnabled: false, borderWidth: pt(0.8), borderColor: col('leaf'),
    color: col('leaf') }),
  chip('jump', { background: col('straw'), color: col('ink') }),
];

chipStylesを宣言すると組み込みの淡い青のチップが置き換わり、styleのないチップには最初のスタイルが当たります(チップスタイル)。角の半径をボックスの高さの半分より大きくするとピル型になります。チップの中では改行しないので、行が切れるのはチップの前後のスペースだけになり、「Sat 11 April」のような日付は1行に収まります。チップスタイルには大文字・小文字を切り替える設定がないため、タグはMarkdownで大文字で入力してあります。上下の内側余白は行の外側に描かれるので、13.4 ptのグリッドは崩れません。

#4 · 絵の横に文章を組む

script.js · 93〜98行コード全体で見る
// wrap sets the drawing at that side of its column, width of it, and the text after the
// ::resource line runs beside it at the measure left over, then under it at full width:
//   #### Sixteen squares by the gate {style="kicker"}
//   ::resource{id="bed"}                     ← 51 mm at the right of the 113 mm column
//   The demonstration bed by the gate is 1.2 metres square …   ← beside it, then under it
const WRAP = { wrap: 'right', width: 0.45 }; // a body line of white between it and the text

wrap: 'right'で苗床の画像を113 mmの段の右端に、段幅の45 %(51 mm)で置くと、::resource行のあとの段落は残りの57 mmで画像の横に組まれ、画像とキャプションから本文1行分離れます(回り込み)。画像の上端は段落の1行目にそろい、すべての行が13.4 ptのグリッドに乗ります。段落がもっと長ければ、1つの段落のまま画像の下で113 mmの全幅に戻ります。画像がまだ本文の横にあるうちに見出しや別の図が来ると、それは画像の下に回ります。上の4レベルの見出しには、色を葉の緑に変えるだけの見出しスタイルを当てています。

#5 · 細いグラフを帯の中央に置く

script.js · 102〜114行コード全体で見る
const drawing = (id, w, h, placement = {}) => ({ id, typeId: 'drawing', kind: 'svg',
  svg: { fileId: `${id}.svg`, width: w * 10, height: h * 10 }, // mm × 10: fitted to the column
  placement: { position: 'here', ...placement }, // drawn where ::resource{id} stands
  caption: CAPTIONS[id][0], note: CAPTIONS[id][1], altText: CAPTIONS[id][2],
  createdAt: 0, updatedAt: 0 });
// width is a fraction of the column and align where the figure sits in it: the text above
// and below never moves into the white either side.
const HEAT = { width: 0.62, align: 'center' };
const resources = () => [drawing('plan', 114, 56.5), drawing('heat', 68, 40, HEAT),
  drawing('bed', 50, 50, WRAP), DRILL];
// Newsletter drawings carry no "Figure 1": an empty prefix prints no label.
const resourceTypes = [{ id: 'drawing', name: 'Drawing', shortLabel: 'Drawing',
  captionPrefix: '', numberingTemplate: '', resetOn: 'never', counterFormat: 'decimal' }];

width: 0.62で、113 mmの段の中のグラフの幅は70.1 mmになり、align: 'center'で左右に21.5 mmずつ紙面が空きます(配置)。上下の本文は行長いっぱいのままで、その余白に流れ込むことはありません。画像はcaptionPrefixが空のリソースタイプに属するので、キャプションは前に「Figure 1」を付けず、それぞれの太字の語から始まります。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 042 · Community newsletter: lead story and briefs ═════
// https://postext.dev/en/cookbook/community-newsletter
// Code: MIT · Text: original (CC BY 4.0) · Drawings: generated in code (CC BY 4.0)
// Fonts: Work Sans, Titan One, Courier Prime (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, inlineSvgFonts,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'community-newsletter';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: garden colours, every one linked by id
// ink: text · leaf: nameplate and headlines · tomato, the accent: tags, tab, column heads ·
// straw: the band · marigold: second tag · tint: pale greens · rule: hairlines · muted: notes
const palette = { ink: '#1d211c', leaf: '#2f6b3a', tomato: '#c43f2a', straw: '#f2d492',
  marigold: '#e2b33c', tint: '#eef4e8', rule: '#cfd3c6', muted: '#5f6659', paper: '#fbfaf5' };
// Each colour carries its hex and the palette entry it follows.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [ // defaults link to 'main-color': point it at the leaf, never blue
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  { id: 'main-color', name: 'leaf (defaults)', value: { hex: palette.leaf, model: 'hex' } },
];
// #endregion
const [TEXT, DISPLAY, LABEL] = ['Work Sans', 'Titan One', 'Courier Prime'];
const SIDE = 16; // mm: the side margins of one A4 sheet, printed on both sides
const LEAD = 13.4; // body leading in pt: the baseline grid
const caps = (size, colour) => ({ fontFamily: LABEL, fontSize: pt(size), fontWeight: 700,
  textTransform: 'uppercase', letterSpacing: pt(size * 0.12), color: col(colour) });
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });

// #region answer: a wide column for the lead, a narrow one for the briefs, one flow
const layout = {
  layoutType: 'oneAndHalf', // the narrow column sits on the right and takes text (the
  // defaults of sideColumnSide and sideColumnRole; 'floats' would keep text out of it)
  sideColumnPercent: 32, // 57 mm of the 178 mm measure
  gutterWidth: mm(8), // the wide column keeps the other 113 mm
  columnRule: { enabled: true, color: col('rule') }, // a 0.5 pt hairline in the gutter
};
// The text runs down the wide column, then the narrow one, then the next page's wide
// column. A :::columnbreak sends the next block on to the following column, so the
// Markdown decides what each column holds:
//   ## Shared compost bays open by the top gate      ← the lead, in the wide column
//   … :chip[Continued on page 2]{style="jump"}
//   :::columnbreak                                    ← the briefs open the narrow column
//   ## In brief {style="rail"}
//   …
//   :::columnbreak                                    ← from the last column: next page

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

アレンジ

#短信を左に置く

読む順は変わらず広い段が先なので、同じMarkdownでトップ記事が右、短信が左に組まれます。

   layoutType: 'oneAndHalf',
+  sideColumnSide: 'left',

#短信をページ幅に並べる

本文は最大2段までです。新聞の第1面では、:::columns{count=4}を使った囲みで、4本の短信をページの下部に横に並べています。

クレジット

レシピ
Ignacio Ferro
本文
書き下ろしの文章, CC BY 4.0
画像
  • The site plan, the temperature chart, the square-metre bed and the row of seedlings under the nameplate, drawn in code in the page's palette · Ignacio Ferro · CC BY 4.0
フォント
Work Sans (SIL OFL 1.1) · Titan One (SIL OFL 1.1) · Courier Prime (SIL OFL 1.1)
Sandbox