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

レシピ集 · 第9章 · 完成した出版物

雑誌の表紙とセクション別の目次

写真の表紙では表紙コピーが題字を基準に並び、目次はセクションごとに色の行を立てて生成されます。各セクションは、ページを開かない部です。

1ページ(全6ページ)

  • 英語の見本:日本語版はまだありません
  • 仕上がり230 × 300 mm
  • 2段, 段間6 mm
  • Spectral 9.5/13.5
  • Bodoni Moda
  • Jost
  • 6ページ
  • レベル
  • Postext 1.57.1
  • 組版時間194 ms
  • コード249行

かんたんな説明

食と農業の雑誌の表紙と最初の数ページです。写真の表紙と目次があり、セクションごとに色を決めて、その色をそのページ全体に通す方法がわかります。

できあがり

架空の食と土地の季刊誌『FALLOW』のある号から、230 × 300mmの6ページです。表紙では118ptのBodoniの題字の下にトスカーナの谷が裁ち落としで広がり、3本の表紙コピーが紙色のパネルに載ります。キッカーはそれぞれセクションの色で、隅に価格とバーコードがあります。2ページ目は生成した目次で、セクションごとに色のタブを立て、その下に記事の題、ノンブル、リードを並べます。右の段には編集長の言葉、寄稿者、奥付が入ります。続くセクションはテラコッタ、オリーブ、ワイン色です。どの記事も、ページの頭に裁ち落としで渡した写真と、その下端に食い込むセクションの色のパネルで始まり、ノンブルのタブ、行頭記号、囲みもその色になります。色を決めるのは各記事の上の:::partで、区切りのページは開きません。

このレシピが答える質問

  • 表紙、小扉、扉、奥付を作るには?
  • 自動で更新される目次(リーダー、ノンブル、著者名、部の行)を追加するには?
  • 本を部や節に分け、それぞれに専用の色と中扉を付けるには?
  • 章ごとに異なる写真、色、章扉のバリエーションを与えるには?

手短な答え

script.js · 39〜74行コード全体で見る
const MASTHEAD = TRIM.width - MARGIN.inner - MARGIN.outer; // the word spans the text block
const PANEL = 84; // mm: the cover lines' panel, a column of paper over the photograph
const SEAM = 0.3; // mm: each box overlaps the one above, so no hairline of photo shows
// A cover line: a kicker in its section's colour over a line in Bodoni, on paper boxes of one
// width. Chained with 'below' they read as one panel, and a longer line pushes the rest down.
const sheet = (top, bottom) => ({ backgroundColor: col('paper'),
  padding: { top: mm(top), right: mm(5), bottom: mm(bottom), left: mm(5) } });
const small = { ...label, fontSize: pt(8), letterSpacing: pt(1.6), color: col('ink') };
const coverLine = (n, colour, above = n === 1 ? '#masthead' : `#line${n - 1}`) => [
  text(`kicker${n}`, `{attr.kicker${n}}`, { ...small, color: col(colour),
    box: sheet(n === 1 ? 5 : 4, 1.5) },
  { ...at(above, 'below', 0, n === 1 ? 8 : -SEAM), size: { width: mm(PANEL) } }),
  text(`line${n}`, `{attr.line${n}}`, { ...bodoni, italic: true, fontSize: pt(15),
    lineHeight: 1.12, color: col('ink'), box: sheet(0, n === 3 ? 5 : 0) }, // line 3 ends the panel
  { ...at(`#kicker${n}`, 'below', 0, -SEAM), size: { width: mm(PANEL) } }),
];
const cover = { enabled: true, slot: { elements: [
  { kind: 'image', id: 'photo', resourceId: 'cover', // the JPEG is cropped to the trim, 23 : 30
    placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: 'fill' } } },
  text('strap', '{subtitle}', small, at('page', 'top-left', MARGIN.inner, 12)), // a recto
  text('issue', '{attr.issue}', { ...small, align: 'right' },
    at('page', 'top-right', -MARGIN.outer, 12)),
  text('masthead', '{titleText}', { ...bodoni, fontWeight: 900, fontSize: pt(118),
    lineHeight: 0.86, // set tight: the masthead is capitals, with no descenders
    letterSpacing: pt(1), textTransform: 'uppercase', align: 'center', color: col('ink') },
  { ...at('#strap', 'below', 0, 6), size: { width: mm(MASTHEAD) } }),
  ...coverLine(1, 'olive'), ...coverLine(2, 'terracotta'), ...coverLine(3, 'wine'),
  // The price and a made-up barcode sit in the corner, anchored to the page, not the words.
  text('price', '{attr.price}', { ...small, fontSize: pt(7), box: sheet(1, 1.5) },
    { ...at('page', 'bottom-right', -MARGIN.outer, -12), size: { width: mm(32) } }),
  { kind: 'image', id: 'barcode', resourceId: 'barcode',
    placement: { ...at('#price', 'above', 0, SEAM), size: { width: mm(32) } } },
] } };
// hook-up: headingStyles gets { id: 'cover', numbered: false, toc: false, advancedDesign: cover,
// footer: { elements: [] } }, with no folio; the Markdown's first line is
// # Fallow {style="cover" issue="…" price="…" kicker1="…" line1="…" … kicker3="…" line3="…"}

材料

種類
Spectral, Bodoni Moda, Jost (SIL OFL 1.1)
素材
  • castellina-cover-1150.jpg
  • castellina-farm-1530.jpg
  • fields-1610.jpg
  • flasks-1920.jpg
  • harvest-1840.jpg
  • Castellina in Chianti (the cover and its copy in the contents) (Rowan Heuvel, CC0 1.0)
  • Castellina in Chianti, a detail (the feature's photograph) (Rowan Heuvel, CC0 1.0)
  • Plants in beakers (the Field notes opener) (chuttersnap, CC0 1.0)
  • Harvesting the wheat crop (the Kitchen opener) (meriç tuna, CC0 1.0)
  • Fields from above near Castellina in Chianti (the feature's opener) (Generated With Diffusion Models, オリジナル)
  • The cover's barcode, drawn in code (Ignacio Ferro, MIT)

作り方

#1 · 表紙を題字から吊り下げる

コードは上の手短な答えにあります。ページに固定しているのは写真、頭の2行、価格だけです。それ以外はすべてほかの要素に固定しています(要素の配置)。題字はストラップの下、最初のキッカーは題字の8mm下、そして各コピーはそのキッカーの下、各キッカーは前のコピーの下です。そのため表紙コピーが長くなったり題字が大きくなったりしても、下にあるものは重なって印字されず、押し下げられます。キッカーとコピーはそれぞれ幅84mmの紙色のボックスが付き、6つのボックスが積み重なってパネルになるので、パネルは言葉に合わせて伸びます。最初のボックス以外は上のボックスに0.3mm重ね(SEAM)、バーコードも同じように価格に重ねます。Canvasでは、接しているだけの2つの塗りのあいだに、写真がヘアラインのように見えてしまうからです。雑誌には半扉も扉もありません。誌名は表紙が、号数、季節、奥付は目次ページが受け持ちます。書籍の前付けについては前付けはローマ数字、本文は1ページからを参照してください。

#2 · 各セクションを、ページを持たない部にする

script.js · 78〜87行コード全体で見る
const parts = { page: false }; // a :::part now only sets the section's title and palette
const story = (id, picture) => ({ id, numbered: false, advancedDesign: opener(picture) });
const headingStyles = () => [
  { id: 'cover', numbered: false, toc: false, advancedDesign: cover,
    footer: { elements: [] } }, // no folio on the cover (the header is empty everywhere)
  { id: 'contents', numbered: false, toc: false, advancedDesign: contentsOpener,
    footer: folioLine('{title}', '{publishDate}') }, // no section yet: the issue instead
  // One opener for every story; the style names its picture, the part its colour.
  story('grain', 'flasks'), story('rest', 'fields'), story('bread', 'harvest'),
];

parts.page: falseにすると、:::part{title="Features" palette="band=#5d6a2b"}のような:::partは区切りのページを開かず、次のブロックから先のセクションの題とパレットを設定するだけです(:::partコンテナー)。各記事のH1はnumbered: falseの見出しスタイルを取るので、目次は番号なしで並べます。スタイルが冒頭の写真を選び、部が色を受け持ちます。

#3 · セクションの色はすべて1つの項目にリンクする

script.js · 14〜27行コード全体で見る
const palette = {
  ink: '#1c1a16', // text: a warm near-black
  paper: '#fbf8f1', // the page, and type set on colour
  band: '#8b6a3e', // the house earth; each :::part fence brings its own 'band'
  muted: '#6b6358', // credits and the standfirsts in the contents
  olive: '#5d6a2b', terracotta: '#a3472a', wine: '#7a2c3a', // as in the :::part fences: edit both
};
// A part overrides by id: col() writes the id beside the hex, and the designs follow it.
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' } })),
  // The engine's defaults link to 'main-color': point it at the ink, so nothing prints blue.
  { id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];

部はパレットの項目をidで上書きするので、セクションとともに変わるものはすべてbandにリンクします。冒頭のパネル、ノンブルのタブ、行頭記号とリストの番号、プルクオート、データ囲みの帯と題です。本文では、上書きは値で行われます。hexがbandの基本のhex(#8b6a3e)と同じ色はすべてセクションの色になるので、ほかの項目はこのhexを使いません。デザイン要素は逆です。部の上書きはpaletteIdを通じてデザイン要素に届くので、col()はhexの横にidを書きます。

#4 · 目次を自分でグループ分けさせる

script.js · 91〜124行コード全体で見る
const mid = at('container', 'left', 0, -1); // the row's middle, 1 mm up: air above the title
const contents = { // passed to the config as `toc`
  levels: [{ level: 1, fontFamily: 'Bodoni Moda', fontSize: pt(17), fontWeight: 600,
    marginBottom: pt(2 * LEAD) }], // in ink, on the body's 13.5 pt leading
  pageNumber: { fontSize: pt(26), width: mm(14) }, // in the levels' Bodoni
  leader: { enabled: false }, subtitle: { enabled: true, attr: 'standfirst', // in italic
    fontFamily: 'Spectral', fontSize: pt(10), color: col('muted') },
  // A part row is a design as wide as the column; its 'band' takes the part's palette. No
  // {pageNumber} in it: each story under the tab prints its own page.
  parts: { height: pt(2 * LEAD), design: { elements: [ // two grid lines (the default: 2 em)
    { kind: 'rule', id: 'line', thickness: pt(0.75), color: col('band'), // behind the tab
      placement: { ...mid, size: { width: 'fill' } } },
    text('tab', '{titleText}', { ...label, fontSize: pt(8), letterSpacing: pt(1.6),
      color: col('paper'), box: { backgroundColor: col('band'),
        padding: { top: mm(1.2), right: mm(2.4), bottom: mm(1.2), left: mm(2.4) } } },
    mid),
  ] } },
};
// The colophon closes the contents page; the Markdown calls it with :::paragraphs.
const colophon = { id: 'colophon', fontFamily: 'Jost', fontSize: pt(7), lineHeight: pt(10),
  color: col('muted'), textAlign: 'left', firstLineIndent: pt(0), marginTop: pt(LEAD) };
const air = { padding: { bottom: mm(9) } }; // empty padding counts: the columns start lower
const contentsOpener = { enabled: true, slot: { elements: [
  { kind: 'rule', id: 'rule', thickness: pt(1), color: col('ink'),
    placement: { ...at('container', 'top-left'), size: { width: 'fill' } } },
  text('kicker', '{titleText}', { ...label, fontSize: pt(9), letterSpacing: pt(1.8),
    color: col('band') }, at('#rule', 'below', 0, 5)),
  text('issue', '{attr.issue}', { ...bodoni, italic: true, fontSize: pt(44), lineHeight: 1.05,
    color: col('ink') }, at('#kicker', 'below', 0, 2)),
  text('strap', '{subtitle}', { fontFamily: 'Spectral', italic: true, fontSize: pt(11),
    color: col('muted'), align: 'left' }, at('#issue', 'below', 0, 1.5)),
  text('number', '{attr.number}', { ...bodoni, fontWeight: 900, fontSize: pt(160), lineHeight: 1,
    align: 'right', color: col('band'), box: air }, at('container', 'top-right', 0, 4)),
] } };

:::tocは記事を並べ、各:::partに、toc.parts.designからその部のパレットで組んだ行を与えます(目次)。そのため1つの行デザインで、3色のタブが3つ印字されます。罫とタブはどちらもmid、つまり行の中心を1mm上げた位置に固定され、タブが下の題にかからないようにしています。リーダーをオフにしているので、題とノンブル(3、4、6)のあいだには何も入らず、subtitle.attrが冒頭の見出しのstandfirst属性を題の下にイタリックで印字します。右の段の最後にある奥付は段落スタイルで、mutedの色のJost 7ptです。Markdownでは:::paragraphs{style="colophon"}で適用します。

#5 · どの記事にも同じ扉を

script.js · 128〜152行コード全体で見る
const PHOTO = 150; // mm from the top edge to the foot of the picture
const FOOT = PHOTO - MARGIN.top; // the same foot from the container, which starts at the margin
const LIFT = 34; // mm: how far the panel rises into the picture
const WIDE = 136; // mm: the panel's width
const panel = (top, bottom) => ({ backgroundColor: col('band'),
  padding: { top: mm(top), right: mm(6), bottom: mm(bottom), left: mm(6) } });
const below = (id) => ({ ...at(`#${id}`, 'below', 0, -SEAM), size: { width: mm(WIDE) } });
const opener = (resourceId) => ({ enabled: true, slot: { elements: [
  { kind: 'image', id: 'picture', resourceId, // fitted, never cropped: each file is 230 : 150
    placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: mm(PHOTO) } } },
  text('credit', '{attr.credit}', { ...small, fontSize: pt(6.5), color: col('muted'),
    letterSpacing: pt(0.6), align: 'right' }, at('container', 'top-right', 0, FOOT + 2)),
  text('section', '{partTitle}', { ...label, fontSize: pt(8.5), letterSpacing: pt(1.7),
    color: col('paper'), box: panel(6, 2) }, { ...at('container', 'top-left', 0, FOOT - LIFT),
    size: { width: mm(WIDE) } }),
  text('title', '{titleText}', { ...bodoni, fontWeight: 700, fontSize: pt(32), lineHeight: 1.02,
    color: col('paper'), box: panel(0, 3) }, below('section')),
  text('standfirst', '{attr.standfirst}', { fontFamily: 'Spectral', italic: true,
    fontSize: pt(11.5), lineHeight: 1.35, overflow: 'wrap', align: 'left',
    color: col('paper'), box: panel(0, 6) }, below('title')),
  // The panel and the byline reach below the picture's foot, so they set where the story
  // starts; the byline's empty padding keeps the first line 5 mm under it.
  text('byline', '{attr.byline}', { ...small, fontSize: pt(7.5), letterSpacing: pt(1.3),
    box: { padding: { top: mm(4), bottom: mm(5) } } }, at('#standfirst', 'below')),
] } });

写真はページの天から裁ち落としで、150mm下まで届きます。bandのパネルが、その下端に34mm食い込みます。パネルは幅136mmの3つのテキストボックスで、それぞれ前のボックスのbelowに連なり、{partTitle}から取ったセクション名、題、リードを収めます。パネルと署名は写真の下端より下まで届くので、記事はいちばん低い要素、つまり署名の下から始まります。署名の空の5mmの下内側余白によって、最初の行は少なくともそれだけ署名から離れます。

#6 · ノンブルにセクション名を添える

script.js · 156〜171行コード全体で見る
const TAB = 6.5; // mm: the tab's side; the words beside it take its height and centre on it
const folioLine = (first, second) => ({ elements: [['even', 'left', 1], ['odd', 'right', -1]]
  .flatMap(([parity, side, s]) => {
    const inward = s > 0 ? 'right-of' : 'left-of'; // from the outer edge towards the gutter
    const beside = (id, content, style, to, gap) => text(id, content, { ...style, align: side },
      { ...at(to, inward, s * gap), size: { height: mm(TAB) } }); // text centres vertically
    return [
      text(`tab-${parity}`, '{pageNumber}', { ...label, fontSize: pt(8), color: col('paper'),
        align: 'center', box: { backgroundColor: col('band') } },
      { ...at('page', `bottom-${side}`, s * MARGIN.outer, -11),
        size: { width: mm(TAB), height: mm(TAB) } }),
      beside(`first-${parity}`, first, { ...small, color: col('band') }, `#tab-${parity}`, 3),
      beside(`second-${parity}`, second, { fontFamily: 'Spectral', italic: true,
        fontSize: pt(8), color: col('muted') }, `#first-${parity}`, 2.5),
    ].map((element) => ({ ...element, parity })); // no pages filter: openers get folios too
  }) });

ノンブルは小口側の地にある6.5mm角のbandの四角に入ります。セクション名はその横、のど寄りに固定し、記事の題はさらにその横に置きます。3つのボックスはどれも高さ6.5mmで、文字を上下中央にそろえているので、同じ中心線を共有します。雑誌は記事の最初のページにもノンブルを印字するので、フッターにpagesの絞り込みはありません。表紙の見出しスタイルはフッターを空にし、目次のスタイルはセクションと記事の位置に誌名と号の季節({title}と{publishDate})を置きます。

レシピの全体

Sandbox
// ═══ Postext Cookbook · Nº 023 · Magazine cover and sectioned contents ═══════════════
// https://postext.dev/en/cookbook/magazine-cover-and-contents
// Code: MIT · Text: original (CC BY 4.0) · Photos: R. Heuvel, chuttersnap, m. tuna (CC0), diffusion
// Fonts: Spectral, Bodoni Moda, Jost (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'magazine-cover-and-contents';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one house colour, 'band', that every section overrides
const palette = {
  ink: '#1c1a16', // text: a warm near-black
  paper: '#fbf8f1', // the page, and type set on colour
  band: '#8b6a3e', // the house earth; each :::part fence brings its own 'band'
  muted: '#6b6358', // credits and the standfirsts in the contents
  olive: '#5d6a2b', terracotta: '#a3472a', wine: '#7a2c3a', // as in the :::part fences: edit both
};
// A part overrides by id: col() writes the id beside the hex, and the designs follow it.
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' } })),
  // The engine's defaults link to 'main-color': point it at the ink, so nothing prints blue.
  { id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion
const TRIM = { width: 230, height: 300 }; // an independent-magazine trim, in mm
const MARGIN = { top: 22, bottom: 20, inner: 16, outer: 14 }; // mirrored
const LEAD = 13.5; // body leading in pt: the baseline grid
const caps = { fontFamily: 'Jost', fontWeight: 600, textTransform: 'uppercase' }; // the label face
const label = { ...caps, align: 'left' }; // design text is centred by default
const bodoni = { fontFamily: 'Bodoni Moda', overflow: 'wrap', align: 'left' };
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const text = (id, content, look, placement) => ({ kind: 'text', id, content, placement, ...look });

// #region answer: the cover, one design slot whose words hang from each other
const MASTHEAD = TRIM.width - MARGIN.inner - MARGIN.outer; // the word spans the text block
const PANEL = 84; // mm: the cover lines' panel, a column of paper over the photograph
const SEAM = 0.3; // mm: each box overlaps the one above, so no hairline of photo shows
// A cover line: a kicker in its section's colour over a line in Bodoni, on paper boxes of one
// width. Chained with 'below' they read as one panel, and a longer line pushes the rest down.
const sheet = (top, bottom) => ({ backgroundColor: col('paper'),
  padding: { top: mm(top), right: mm(5), bottom: mm(bottom), left: mm(5) } });
const small = { ...label, fontSize: pt(8), letterSpacing: pt(1.6), color: col('ink') };
const coverLine = (n, colour, above = n === 1 ? '#masthead' : `#line${n - 1}`) => [
  text(`kicker${n}`, `{attr.kicker${n}}`, { ...small, color: col(colour),

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

アレンジ

#題字をハウスカラーで組む

題字を、目次ページの大きな14と同じ土色にします。

-    textTransform: 'uppercase', align: 'center', color: col('ink') },
+    textTransform: 'uppercase', align: 'center', color: col('band') },

#各セクションを区切りのページで始める

独自のページを開く部と、目次の各部の行にノンブルを付ける方法は、ひとつの属性で部ごとに色を変えるを参照してください。

よくあるつまずき

つまずき

'top'のフロートは参照ページの先頭を許さない限り次のページに置かれる

既定では、フロートが自分の参照より上に置かれることはありません。そのため、Nページで参照したページ幅の'top'フロートはN+1ページの頭に置かれます。リソースまたはその種類のdefaultPlacementにplacement.citingPage: trueを設定すると(本全体ならlayout.floatsAtCitingPage、postext 1.25から)、layout.maxTopFraction以内に収まり参照行がそのページに残る場合は代わりにNページの先頭に置かれ、参照より前の本文はその下に送られます。章の最初のページと強制改ページの後のページの先頭には置かれません。その場合は次のページに置かれ、'auto'または'bottom'なら参照したページの下端に入れられます。 図の配置 →

つまずき

ビットマップの印刷サイズは解像度で決まる。印刷用のピクセル数を計算せず、解像度を宣言する

解像度のないビットマップは、文書のdpiで1ピクセルを1レイアウトピクセルとして置かれるため、2400 pxの写真は150 dpiのページで幅406 mmになります。ファイルの実際のピクセル数を宣言し、画像に解像度を与える(bitmap.resolution: 300)か、すべてのビットマップにlayout.bitmapResolutionを設定します。値はppi、またはファイルが記す解像度を読む'file'です。段の幅は引き続き画像の上限になります。 リソースとしての図と表 →

  • 画像要素は写真をボックスの中に収め、切り抜くことはありません。各JPEGをあらかじめボックスに合わせて切っておきます。表紙は23 : 30、扉は230 × 150mmです。そうしないと写真が縮み、縁に白い帯が残ります。
  • 本文では、部はbandにリンクしているかどうかにかかわらず、hexがbandの基本のhexと同じ色をすべて塗り替えます。このhexは、セクションとともに変えたいものだけに使ってください。
  • 記事は両方の言語でコピーフィットしています。スペイン語版の「Field notes」は1ページに収まるようにいくつかの文を短くし、英語版の特集は4ページ目の両段の末尾がそろうように1文から3語を削りました。編集したあとは、数行だけ新しいページにはみ出す記事がないこと、そして記事の最終ページ以外のすべてのページで段末がそろっていることを確認してください。

クレジット

レシピ
Ignacio Ferro
本文
書き下ろしの文章, CC BY 4.0
画像
  • Castellina in Chianti (the cover and its copy in the contents) · Rowan Heuvel · CC0 1.0
  • Castellina in Chianti, a detail (the feature's photograph) · Rowan Heuvel · CC0 1.0
  • Plants in beakers (the Field notes opener) · chuttersnap · CC0 1.0
  • Harvesting the wheat crop (the Kitchen opener) · meriç tuna · CC0 1.0
  • Fields from above near Castellina in Chianti (the feature's opener) · Generated With Diffusion Models · オリジナル
  • The cover's barcode, drawn in code · Ignacio Ferro · MIT
フォント
Spectral (SIL OFL 1.1) · Bodoni Moda (SIL OFL 1.1) · Jost (SIL OFL 1.1)
Sandbox