かんたんな説明
地方の週刊新聞の第1面と2ページ目。大きな見出しをページいっぱいに渡し、短いニュースを並べた帯をページの下に置く方法を示します。
できあがり
架空の谷あいの週刊紙『The Elverdale Courier』の第1面と2ページ目を、246 × 328 mmの紙に組みます。ブラックレターの題字が天気予報の耳と価格の耳の間に座り、その下に太い罫と細い罫、日付行が続きます。トップ記事は、Libre Franklin Blackの56 ptで両段にまたがる2行の大見出し、イタリックの副見出し、幅222 mmの写真の帯で始まり、細い罫で区切られた両端そろえの2段で続きます。下端では4本の短信が色を敷いた帯を1段ずつ分け合い、それぞれ赤いチップで始まります。2ページ目は赤い欄名で始まり、コードで描いた図を添えた橋の記事、右の段の頭に置いた5日間の天気予報、ページを横切る2つ目の見出し、投書欄、各行に棒の付いた区ごとの投票結果の表を収めます。
このレシピが答える質問
- Postextは3段以上の段組みや、画像の周りへの回り込みに対応していますか?
- ページの途中に、2段をまたぐ囲み(3つ並びの「数字で見る」欄など)を置くには?
- 図の位置を制御するには(ページの上端、2段をまたぐ、まさにこの位置、余白)?
- 章タイトルをページ幅いっぱいに置き、その下で本文を2段組みにするには?
手短な答え
const layout = { layoutType: 'double', gutterWidth: mm(GUTTER), // the body of every page
columnRule: { enabled: true, color: col('rule'), lineWidth: pt(0.5) } };
// The strip is a tinted, titled box, so its four columns are a :::columns group in a :::callout.
// The fence spans the page and floats the box to the foot, so the story fills the columns above:
// :::callout{type="briefs" span="page" placement="bottom" title="In brief"}
// :::columns{count=4 breaks="2,3,4"} ← each brief opens a column (child 2, 3 and 4)
// …four paragraphs…
// :::
// :::
// The style could carry span and placement too; on the fence they stay in sight in the text.
// hook-up: config() takes layout as it is and lists briefs in calloutStyles.
const briefs = { id: 'briefs',
background: col('tint'), // one device: a tint, no stripe or border
padding: { top: mm(3), right: mm(4), bottom: mm(4), left: mm(4) },
columnGap: mm(GUTTER), // the inner columns keep the page's gutter
titleStyle: { ...caps(9, 800, 'flag'), gap: mm(2) },
body: { fontFamily: 'PT Serif', fontSize: pt(8.6), lineHeight: pt(11.4), textAlign: 'left',
firstLineIndent: pt(0) } }; // ragged and unindented, unlike the columns
材料
- 機能
- 段抜きの囲み囲みの中や本文中の段組みフロートする囲みデザインした章扉段抜きの章見出し帯見出しスタイル見出しの属性デザイン要素の基準位置ページデザインのテキスト・罫・ボックス柱とノンブル段間罫囲みインラインのチップ段落スタイル図の配置その場に置く図図版とボックスの回り込み名前付きの表スタイル独自のリソースの種類表のセル内の画像
- 種類
- Grenze Gotisch, PT Serif, Libre Franklin (SIL OFL 1.1)
- 素材
ridge-2400.jpg- Wind turbines on a snowy ridge (the front-page photograph, cropped to a band) (Jason Blackeye, CC0 1.0)
- The bridge drawing and the bars in the ward table, drawn in code in the page's palette (Ignacio Ferro, CC BY 4.0)
作り方
#1 · 新聞用紙、インク、赤1色
const palette = {
ink: '#111315', // text and the heavy rules: a cold near-black
paper: '#f8f5ee', // newsprint, and type reversed out of ink or red
flag: '#a6192e', // the one accent: section flags, kickers, the Yes bars
tint: '#ebe6db', // the In brief strip
rule: '#9a978f', // hairlines: the column rule, table rules
muted: '#5d5a55', // bylines, the folio line's title and date, credit notes, the imprint
};
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [ // defaults link to 'main-color': point it at the ink, never blue
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
{ id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
ページは新聞用紙の色(#f8f5ee)、文字は黒に近いインキ(#111315)です。ただ1つの赤、#a6192eは、欄名、見出し上のラベル、チップ、賛成の棒に使います。各色はpaletteIdでパレットの項目に結び付けてあります。main-colorはインキを指すので、太字、イタリック、2ページ目の2つの参照、設定で指定しなかった既定値はすべてインキで印刷されます。元の値のままなら、これらは既定の青、#295AA3で印刷されます。
#2 · 題字は第1面のH1
const NAME = 52; // pt: the blackletter nameplate
const EAR = 31; // mm: each ear, in the room the nameplate leaves at either side
const EAR_DROP = 1.8; // mm: measured so the ears' big figures sit on the nameplate's baseline
const AIR = 2; // mm between the lower rule and the masthead's foot, where the banner box starts
const ear = (side, lines) => lines.map(([id, content, look], i) => text(id, content,
{ ...look, align: side }, { ...(i === 0 ? at('container', `top-${side}`, 0, EAR_DROP)
: at(`#${lines[i - 1][0]}`, 'below', 0, 1)), size: { width: mm(EAR) } }));
const serif = { fontFamily: 'PT Serif', fontSize: pt(9), italic: true, color: col('ink'),
lineHeight: 1.25 };
const nameplate = { enabled: true, slot: { elements: [
depth(7), // the masthead is seven grid lines deep; the rules and dateline hang from its foot
{ kind: 'rule', id: 'foot', thickness: pt(0.5), color: col('ink'),
placement: { ...at('#depth', 'align-bottom', 0, -AIR), size: { width: 'fill' } } },
...[['left', '{attr.issue}'], ['center', '{publishDate}'], ['right', '{attr.area}']].map(
([align, content]) => text(`date-${align}`, content, { ...caps(7.5, 600), align },
{ ...at('#foot', 'above', 0, -1.4), size: { width: 'fill' } })),
rule('thin', '#date-left', 0.5, 1.6), rule('heavy', '#thin', 2.5, 0.6), // the Oxford rule
text('name', '{titleText}', { fontFamily: 'Grenze Gotisch', fontSize: pt(NAME),
fontWeight: 700, lineHeight: 1, align: 'center' },
{ ...at('#heavy', 'above', 0, -1.2), size: { width: 'fill' } }), // centred between the ears
...ear('left', [['w-kicker', 'Weather', caps(7, 700, 'flag')],
['w-outlook', '{attr.outlook}', serif], ['w-temps', '{attr.temps}', franklin(15, 800)]]),
...ear('right', [['p-kicker', '{attr.since}', caps(7, 700, 'flag')],
['p-day', '{attr.day}', serif], ['p-price', '{attr.price}', franklin(15, 800)]]),
] } };
// hook-up: headingStyles gets { id: 'front', advancedDesign: nameplate, header: { elements:
// [] } }, H1 already spans the page, and the Markdown opens with
// # The Elverdale Courier {style="front" issue="…" area="…" outlook="…" temps="…" since="…"
// day="…" price="…"}
# The Elverdale Courierはfront見出しスタイルを使い、見出しのテキストと7つの属性(issue、area、outlook、temps、since、day、price)から題字部分を埋めます。日付はフロントマターのpublishDateから取ります。グリッド7行分(31.1 mm)の高さの空のボックスが、冒頭部分の高さを決めます。罫、日付行、題字はその下端に固定されているので、冒頭部分はグリッド線の上で終わります。
#3 · 両段にまたがる見出しは囲みにする
// :::callout{type="banner" span="page" title="Transport"} ← an optional kicker, then the H2
const banner = { id: 'banner', backgroundEnabled: false,
padding: { top: pt(0), right: pt(0), bottom: pt(0), left: pt(0) },
titleStyle: { ...caps(8, 800, 'flag'), gap: mm(1.2) }, // a kicker, when the fence has a title
marginTop: pt(0), // flush under the nameplate or the section flag
marginBottom: pt(LEAD / 2), // half a line, then the columns start on the next grid line
body: { fontFamily: 'PT Serif', fontSize: pt(13), lineHeight: pt(16.5), textAlign: 'left' } };
// A story that starts mid-page: the same box under a rule. The columns above it are cut level.
const story = { ...banner, id: 'story', marginTop: pt(LEAD),
stripe: { enabled: true, side: 'top', width: pt(1), color: col('ink') }, // its one device
padding: { top: mm(2.5), right: pt(0), bottom: pt(0), left: pt(0) } };
// Inside the box the headline is an H2 in a heading style: one size for each rank of story.
const headline = (id, size, look = {}) => ({ id, fontSize: pt(size), lineHeight: pt(size * 1.02),
marginBottom: pt(size * 0.2), ...look }); // tight leading, a fifth of it below
見出しが両段にまたがるのは冒頭部分(章扉)としてだけで、章扉は新しいページを始めます。区の記事で、囲みではなくH2にspan: 'page'を付けると、その記事は3ページ目に移ります。span="page"を指定した枠なしの囲みなら、ページの途中から始められます。2ページ目では、段はその上で高さをそろえて切られ、下で再開します。囲みには3つの見出しスタイル(56、30、22 pt)のいずれかで組んだH2、イタリックの副見出し、第1面ではさらに写真が入ります。marginBottomを半行分にしているので、段は次のグリッド線から始まり、2ページ目では副見出しの3.4 mm下になります。既定のアキでは間隔が7.8 mmになり、投書欄が3ページ目にはみ出します。
#4 · 4段の短信欄は囲みにする
この手順のコードは上の手短な答えにあります。どちらのページも本文は2段組みです(レイアウトの種類)。短信が4段になるのは1ページ目の下端だけで、題と地色も付くので、囲みに入れます。ここではページ幅の囲みに:::columnsのグループを入れています。breaksはグループのブロックを数えます。短信1本が1ブロックなので、短信2、3、4がそれぞれ2、3、4段目を始めます。各段は幅49 mmで、間にはページと同じ6 mmの段間を取ります。
:::callout{type="briefs" span="page" placement="bottom" title="In brief"}
:::columns{count=4 breaks="2,3,4"}
:chip[TRANSPORT]{style="flag"} **Bus 44 back on Sundays.** The Elverdale to Kirkby bus …
:chip[SCHOOLS]{style="flag"} **An orchard for Brook Lane.** Pupils at Brook Lane …
…
:::
:::placement="bottom"はこの囲みを1ページ目の下端にフロートさせ、囲みは36.9 mmを占めます。記事はその上の83 mmの段を埋めます。トップ記事の写真は、大見出しの囲みの中で両段にまたがる帯のままです。本文は段より狭い図版の片側にだけ回り込み、2段にまたがる図版の周りには回り込みません。2ページ目の橋の図は横に本文を組んでいます(手順5)。
#5 · 図版はインライン、表はフロート
// A caption label prints only when captionPrefix has text: '' leaves no "Figure 1".
const unnumbered = (id, name, captionStyle) => ({ id, name, shortLabel: name, captionPrefix: '',
numberingTemplate: '', resetOn: 'never', counterFormat: 'decimal', captionStyle });
const resourceTypes = [unnumbered('picture', 'Picture'), // captions under the picture
unnumbered('panel', 'Panel', { position: 'above', fontSize: pt(9.5) })]; // tables: titled above
const resource = (id, typeId, kind, body, extra) => ({ id, typeId, kind, [kind]: body,
createdAt: 0, updatedAt: 0, ...extra });
const resources = [
// Set inline in the page-span banner box: a 'top' float never lands above the line that
// cites it (gotcha: top-float-next-page). It keeps the float gap above it, inside the box too.
// 2400 px at 150 dpi is 406 mm: the photo shrinks to the box (gotcha: bitmap-print-size).
resource('ridge', 'picture', 'bitmap', { fileId: 'ridge-2400.jpg', format: 'jpeg', width: 2400,
height: 800 }, { placement: { position: 'here' },
altText: 'Wind turbines on a snow-covered ridge under a bright, cloudy sky.',
caption: '**File picture:** turbines on an upland ridge. Each of the three planned for '
+ 'Harrow Ridge would generate 2.3 megawatts.',
note: 'Photograph: Jason Blackeye, CC0, via Wikimedia Commons' }),
// Drawn in code (the art region) and set inline, where ::resource puts it in column 1,
// at the column's right with the next paragraph running beside it (text wrap).
resource('bridge', 'picture', 'svg', { fileId: 'bridge.svg', width: 1190, height: 460 },
{ placement: { position: 'here', wrap: 'right', width: 0.47 },
altText: 'Drawing of a two-arch stone bridge between sloping river banks; under its '
+ 'central pier, a red concrete footing.',
caption: '**The rebuilt pier.** Its new concrete footing (red) goes six metres below the '
+ 'riverbed. Both arches were relaid with their own stones.',
note: 'Drawing: The Courier' }),
// A page-span 'bottom' float sits under both columns of the page that cites it. On the last
// page it follows the balanced columns, so the copy there is fitted to bring it to the foot.
resource('wards', 'panel', 'table', { styleId: 'results', model: resultsTable() },
{ placement: { position: 'bottom', span: 'page' }, caption: '**How the wards voted**',
note: 'Red: yes. Grey: no. The black line marks half the vote. '
+ 'Source: Elverdale Town Council.' }),
// A column 'top' float waits for the head of the next column with room.
resource('forecast', 'panel', 'table', { styleId: 'forecast', model: forecastTable() },
{ placement: { position: 'top', span: 'column' }, caption: '**The next five days**',
note: 'Sunrise 6.57, sunset 19.03 on Thursday. Forecast: Wend Valley Weather Station.' }),
];
写真を大見出しの囲みの中にインラインで置くのは、ページ幅のtopフロートが、それを参照する行より上には決して置かれないからです。フロートにすると、写真は2ページ目の頭に来ます(よくあるつまずきを参照)。橋の図も、橋脚についての段落の後にインラインで置き、wrap: 'right'とwidth: 0.47で1段目の右に段幅の47 %で置きます。続く段落はその横に組まれ、下では全幅に戻ります(回り込み)。この幅なら横の行が間延びしません。記事の原稿は低くなった図に合わせて調整し直してあります。天気予報は段の頭にフロートし、右の段の上端に収まります。区の表は両段の下、段間の罫が止まる位置にフロートします。最後のページでは表が段末をそろえた段のすぐ下に付くので、表が下端まで下りるように、上の原稿を調整してあります。どちらのリソースの種類もcaptionPrefix: ''を設定しています。キャプションのラベルはプレフィックスに文字があるときだけ印刷されるので、「Figure 1」で始まるキャプションはありません。
#6 · 中面は欄名で始まる
const section = { enabled: true, slot: { elements: [
depth(2), // two grid lines: the flag sits on a 3 pt bar, 1.6 mm above the foot
{ kind: 'rule', id: 'bar', thickness: pt(3), color: col('ink'),
placement: { ...at('#depth', 'align-bottom', 0, -1.6), size: { width: 'fill' } } },
text('flag', '{titleText}', { ...caps(11, 800, 'paper'), box: { backgroundColor: col('flag'),
padding: { top: mm(1.3), right: mm(3), bottom: mm(1.1), left: mm(3) } } },
at('#bar', 'above')),
] } };
const FOLIO = 6; // mm from the top edge to the folio line; its rule 4 mm lower
const folio = (parity, side, s) => [ // s: +1 on a verso (folio on the left), −1 on a recto
text(`n-${parity}`, '{pageNumber}', { ...franklin(9, 800), align: side },
at('page', `top-${side}`, s * MARGIN.side, FOLIO)),
text(`t-${parity}`, '{title} · {publishDate}', { ...caps(7, 600, 'muted'), align: side },
at(`#n-${parity}`, s > 0 ? 'right-of' : 'left-of', s * 3, 0.9)),
].map((element) => ({ ...element, parity }));
const header = { elements: [...folio('even', 'left', 1), ...folio('odd', 'right', -1),
{ kind: 'rule', id: 'folio-rule', thickness: pt(0.5), color: col('ink'),
placement: { ...at('page', 'top-left', MARGIN.side, FOLIO + 4), size: { width: mm(TRIM.width
- 2 * MARGIN.side) } } }] };
# Town & ValleyはH1で、そのbreakBeforeのパリティは'any'です。そのためこの欄は、前に白ページを挟まずに2ページ目を始めます。デザインは3 ptの帯の上の赤い欄名で、グリッド2行分の高さの空のボックスに固定します。ノンブル行はページ上端から6 mm下に固定したヘッダーで、偶数ページ用と奇数ページ用の2種類があります。第1面のスタイルはヘッダーを空にするので、題字の上にノンブル行は印刷されません。
レシピの全体
// ═══ Postext Cookbook · Nº 027 · Newspaper front page ═══════════════════════════
// https://postext.dev/en/cookbook/newspaper-front-page
// Code: MIT · Text: original (CC BY 4.0) · Photo: Jason Blackeye (CC0)
// Fonts: Grenze Gotisch, PT Serif, Libre Franklin (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 = 'newspaper-front-page';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: newsprint, ink and one red for the section flags
const palette = {
ink: '#111315', // text and the heavy rules: a cold near-black
paper: '#f8f5ee', // newsprint, and type reversed out of ink or red
flag: '#a6192e', // the one accent: section flags, kickers, the Yes bars
tint: '#ebe6db', // the In brief strip
rule: '#9a978f', // hairlines: the column rule, table rules
muted: '#5d5a55', // bylines, the folio line's title and date, credit notes, the imprint
};
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [ // defaults link to 'main-color': point it at the ink, never blue
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
{ id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion
const TRIM = { width: 246, height: 328 }; // mm: a 3 : 4 compact, smaller than a tabloid
const MARGIN = { top: 14, bottom: 15, side: 12 }; // newspaper margins: narrow, not mirrored
const GUTTER = 6; // mm between the two body columns, and between the In brief columns
const LEAD = 12.6; // body leading in pt: the baseline grid
const franklin = (size, weight, look = {}) => ({ fontFamily: 'Libre Franklin',
fontSize: pt(size), fontWeight: weight, color: col('ink'), ...look });
const caps = (size, weight, colour = 'ink') => franklin(size, weight, { color: col(colour),
textTransform: 'uppercase', letterSpacing: pt(size * 0.16) }); // capitals tracked 0.16 em
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, align: 'left',
overflow: 'wrap', color: col('ink'), ...look, placement }); // design text defaults to centred
// and black, and a header's text to an ellipsis
// A rule across the slot whose bottom sits `gap` mm above the element it names.
const rule = (id, under, weight, gap = 0) => ({ kind: 'rule', id, thickness: pt(weight),
color: col('ink'), placement: { ...at(under, 'above', 0, -gap), size: { width: 'fill' } } });
// An empty box exactly `lines` grid lines deep sets an opener's depth, and the rest hangs from
// its foot: the opener ends on a grid line, where the columns and their rule begin.
const depth = (lines) => ({ kind: 'box', id: 'depth', style: {}, placement: {
...at('container', 'top-left'), size: { width: 'fill', height: pt(lines * LEAD) } } });
組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)
アレンジ
#短信を写真の下に置いたままにする
content.en.mdでplacement="bottom"を外すと、帯はブロックを書いた位置、つまり写真のすぐ下にとどまり、トップ記事はその下をページの下端まで続きます。
-:::callout{type="briefs" span="page" placement="bottom" title="In brief"}
+:::callout{type="briefs" span="page" title="In brief"}よくあるつまずき
つまずき
'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'です。段の幅は引き続き画像の上限になります。 リソースとしての図と表 →
- 写真に
placement: { position: 'top', span: 'page' }を与えると、写真は1ページ目から2ページ目に移り、そこに単独で置かれます。すると1ページ目の記事は短信欄の92 mm上で終わり、Town & Valleyの欄は3ページ目に移ります。
クレジット
- 本文
- 書き下ろしの文章, CC BY 4.0
- 画像
- Wind turbines on a snowy ridge (the front-page photograph, cropped to a band) · Jason Blackeye · CC0 1.0
- The bridge drawing and the bars in the ward table, drawn in code in the page's palette · Ignacio Ferro · CC BY 4.0
- フォント
- Grenze Gotisch (SIL OFL 1.1) · PT Serif (SIL OFL 1.1) · Libre Franklin (SIL OFL 1.1)


