简单来说
一篇自然杂志的专题报道,开头是一张横贯页面上方的大照片。示例演示怎样排标题、导语、作者和摄影署名,以及后面的方框和结尾小方块。
成品一览
虚构自然杂志《Boreal》冬季号的专题部分,页面尺寸225 × 297 mm。文章以一幅横贯页面上部出血的山间湖泊照片开篇。图片下方,加了字距的眉题压在两行主标题之上,主标题右侧是斜体导语,导语下面是署名;摄影师的出处排在照片下方。主标题就是Markdown标题的文字,眉题、导语、署名和出处都是它的属性。正文在一个跨页上接续,分两栏两端对齐。左页有一个悬挂引号的引文框,右栏顶部有一个资料框;右页上部有一条松林图带,页脚有一个深色数字栏。文章以一个小方块结束。翻过这页,一篇野外指南沿用同一个首页设计,换成插画和铁锈色眉题。
这道食谱解答
- 怎样给章首页加作者行、提要或带首字下沉的导语?
- 怎样给每章不同的照片、颜色或章首页样式?
- 怎样排题词、献词、署名,或带大号引号的引文框?
简短回答
const TOP = 22; // top margin in mm: an opener's container starts here
const sans = { fontFamily: 'Instrument Sans', fontWeight: 600, textTransform: 'uppercase' };
const HEAD = 118; // mm: the headline's measure; the standfirst takes the rest of the line
// Empty padding paints nothing but counts: the story starts on the first grid line at least
// 5 mm under the lower of the headline and the byline, however many lines each one runs to.
const air = { padding: { bottom: mm(5) } };
const at = (id, edge, x, y, width) => ({ anchor: { to: id, edge },
offset: { x: mm(x), y: mm(y) }, ...(width && { size: { width: mm(width) } }) });
const opener = (resourceId, depth) => ({ // depth: how far down the page the picture bleeds
enabled: true, // no minHeight: the story starts under the headline and byline (see air)
slot: {
elements: [ // the photo is an element, not a float: no float reaches the trim
{ kind: 'image', id: 'photo', resourceId, placement: { anchor: { to: 'bleed',
edge: 'top-left' }, size: { width: 'fill', height: mm(depth) } } },
// The photo hangs from the page's top edge, the words from the container, TOP mm lower:
// depth − TOP is the photo's foot, so the credit sits 2 mm under it and the kicker 9 mm.
{ kind: 'text', id: 'credit', content: '{attr.credit}', ...sans, fontWeight: 500,
fontSize: pt(6.5), letterSpacing: pt(0.6), color: col('muted'), align: 'right',
placement: at('container', 'top-right', 0, depth - TOP + 2) },
{ kind: 'text', id: 'kicker', content: '{attr.kicker}', ...sans, fontSize: pt(8.5),
letterSpacing: pt(1.7), color: col('lake'), align: 'left',
placement: at('container', 'top-left', 0, depth - TOP + 9) },
{ kind: 'text', id: 'headline', content: '{titleText}', fontFamily: 'Instrument Serif',
fontSize: pt(58), color: col('ink'), align: 'left', box: air, // wraps: a heading design
lineHeight: 0.94, // tight: the two lines of the headline nearly touch
placement: at('#kicker', 'below', 0, 2.5, HEAD) },
{ kind: 'text', id: 'standfirst', content: '{attr.standfirst}', italic: true,
fontFamily: 'Instrument Serif', fontSize: pt(13.5), lineHeight: 1.22, // a multiple
color: col('ink'), align: 'left',
placement: at('#headline', 'right-of', 7, 3.2) }, // wraps at the container's edge
{ kind: 'text', id: 'byline', content: '{attr.byline}', ...sans, fontSize: pt(7.5),
letterSpacing: pt(1.3), color: col('ink'), align: 'left', box: air,
placement: at('#standfirst', 'below', 0, 3.5) },
],
},
}); // hook-up: headings.levels[0] = { level: 1, span: 'page', breakBefore, advancedDesign:
// opener('lake', 160) }. {titleText} prints the heading's text, {attr.<key>} its <key>="…":
// # The Lake That Keeps Time {kicker="…" standfirst="…" byline="…" credit="…"}
用料
- 功能
- 设计过的章首页页面设计中的图片标题属性浮动框框内或正文中的分栏行内标签从右页开始的章通栏章首色带书眉与页码各栏齐底图的放置锚定设计元素框图标与角标标注框作为资源的图和表标题样式语义调色板按页面角色显示书眉来源与出处行按篇配色
- 类型
- Literata, Instrument Serif, Instrument Sans(SIL OFL 1.1)
- 素材
lake-2000.jpgthaw-2000.jpg- Clouds mirrored in a mountain lake (the opener photograph) (Ales Krivec, CC0 1.0)
- Walk in a thawing forest (the photo band) (Hannah Donze, CC0 1.0)
做法
#1 · 用标题行搭出首页
代码见上面的简短回答。每个{attr.<key>}印出文章#行上<key>="…"的值,{titleText}印出标题本身(标题属性),所以每篇文章的文字都留在自己的Markdown里,所有一级标题共用一个设计。照片挂在页面顶边,容器从下方22 mm处开始,所以depth - TOP就是照片下边缘相对容器的位置;出处在这条线下方2 mm处靠右上,眉题在其下方9 mm处靠左上。主标题用below排在眉题之下,宽度为118 mm的HEAD行长。导语用right-of排在主标题右侧,不设宽度,因此在容器边缘折行;署名用below排在导语之下,导语变长时会把署名往下推,而不会压到它。这一层不设minHeight。主标题和署名各以一段5 mm的空白内边距结尾,这段内边距计入首页高度,所以不论两者各排几行,正文都从两者中较低那个下方至少5 mm处的第一条网格线开始。
#2 · 按真实像素一次性声明图片
// The pictures are not numbered: their own type, with an empty caption prefix and template,
// keeps a figure number off the pine wood's caption.
const photoType = { id: 'photo', name: t({ en: 'Photograph', es: 'Fotografía' }),
shortLabel: t({ en: 'photo', es: 'foto' }), captionPrefix: '', numberingTemplate: '',
resetOn: 'never', counterFormat: 'decimal' };
const PX = 10; // the drawing's pixels per mm
const resources = [
{ id: 'lake', typeId: 'photo', kind: 'bitmap', createdAt: 0, updatedAt: 0, // never cited:
// the opener fits it inside its box, so the JPEG is cropped to the box, 225 × 160 mm
bitmap: { fileId: 'lake-2000.jpg', format: 'jpeg', width: 2000, height: 1422 },
altText: t({ en: 'A still mountain lake mirroring clouds between autumn slopes.',
es: 'Un lago de montaña en calma que refleja las nubes entre laderas otoñales.' }) },
{ id: 'thaw', typeId: 'photo', kind: 'bitmap', createdAt: 0, updatedAt: 0,
// Pixels at the page's 150 dpi (gotcha: bitmap-print-size): 2000 px make 339 mm, so the
// band shrinks to the 195 mm measure. At 300 dpi it would print 169 mm wide.
bitmap: { fileId: 'thaw-2000.jpg', format: 'jpeg', width: 2000, height: 944 },
// A top float opens the page after its ::resource line (gotcha: top-float-next-page):
// the line sits on the verso, so the band heads the recto.
placement: { position: 'top', span: 'page' },
caption: t({ en: 'Early March in the pine wood above the shore: the snow goes first where '
+ 'the sun reaches the ground, weeks before the ice lets go of the lake.',
es: 'Principios de marzo en el pinar sobre la orilla: la nieve se retira primero donde el '
+ 'sol llega al suelo, semanas antes de que el hielo suelte el lago.' }),
note: t({ en: 'Photograph: Hannah Donze, CC0, via Wikimedia Commons',
es: 'Fotografía: Hannah Donze, CC0, vía Wikimedia Commons' }),
altText: t({ en: 'A walker on a snowy path between tall pines.',
es: 'Un caminante en un sendero nevado entre pinos altos.' }) },
{ id: 'ice-art', typeId: 'photo', kind: 'svg', createdAt: 0, updatedAt: 0, // drawn below
svg: { fileId: 'ice-art.svg', width: TRIM * PX, height: ART * PX },
altText: t({ en: 'A lake in section: snow, white ice, black ice and water under a low sun.',
es: 'Un lago en sección: nieve, hielo blanco, hielo negro y agua bajo un sol bajo.' }) },
];
设计元素按资源id指定图片,所以首页的照片像普通图一样声明,但从不被引用:只有首页设计绘制它,并一直画到裁切边,浮动体到不了那里。位图按页面的150 dpi计量,所以松林图的2000 px合339 mm,缩到195 mm行长后,印刷精度约260 dpi。这些图片有自己的资源类型,题注前缀和编号模板都为空,所以松林图的题注不带图号。图带是一个通页宽的top浮动体,而顶部浮动体会放到引用它的那一页的下一页。它的::resource行在左页、1944年那一段之后,所以图带排在右页顶部。
#3 · 把引号悬挂到页边
// The glyph is centred in an icon square that the box keeps as a column, size + gap wide,
// left of the text. A negative gap pulls the text back over the square's empty right side,
// and a left padding of −(size + gap) moves that column out into the margin, so the text
// starts on the column's edge and the mark hangs outside it. The frame stays on the column
// (a background would stop short of the mark). « sits lower and runs wider than “, so the
// Spanish mark is set smaller.
const MARK = t({ en: { glyph: '“', size: 50, column: 34 }, // pt; the column is 12 mm
es: { glyph: '«', size: 28, column: 22.5 } });
// The paddings are optical: once the next paragraph snaps to the grid, the quote has
// the same air above and below it, in both languages.
const quote = { id: 'pullquote', backgroundEnabled: false, marginTop: pt(LEAD),
marginBottom: pt(0), padding: { top: pt(8), right: pt(0), bottom: pt(7),
left: pt(-MARK.column) }, // negative: the icon column starts out in the margin
icon: { kind: 'glyph', glyph: MARK.glyph, fontFamily: 'Instrument Serif',
size: pt(MARK.size), color: col('lake') },
titleStyle: { gap: pt(MARK.column - MARK.size) }, // negative too: size + gap = column
body: { fontFamily: 'Instrument Serif', fontSize: pt(19), lineHeight: pt(1.5 * LEAD),
textAlign: 'left', hyphenation: false, color: col('lake'), // display type: no hyphens
italicColor: col('lake'), firstLineIndent: pt(0) } };
字形图标在文字旁边自占一栏,这会让引文缩进。负的间距把文字挪回到字形方框右侧的空白上。再设一个负的左内边距,宽度等于这一栏剩下的部分(字号加间距,34 pt),把这一栏移到页边里,文字就重新从栏边开始。框的边框仍留在栏内,所以背景色会在引号之前截止。方框从栏外12 mm处开始,居中其中的引号伸入左页14 mm外侧页边约6 mm。西班牙语版把«排得小一些,因为角引号比弯引号位置更低、也更宽。
#4 · 把框浮动到栏顶和页脚
// Floated boxes keep one body line from the text, so they need no margins of their own.
const glance = { id: 'glance', placement: 'top', // floats to the next column head: no hole
backgroundEnabled: false, // one device, the stripe; the text keeps the column's edges
stripe: { enabled: true, side: 'top', width: pt(2.5), color: col('lake') },
padding: { top: mm(2.5), right: pt(0), bottom: pt(0), left: pt(0) },
titleStyle: { ...sans, fontWeight: 700, fontSize: pt(7.5), letterSpacing: pt(1.5),
color: col('lake'), gap: mm(2) },
body: { fontFamily: 'Instrument Sans', fontSize: pt(8.6), lineHeight: pt(12.2),
textAlign: 'left', hyphenation: false, firstLineIndent: pt(0) } }; // ink from bodyText
const numbers = { id: 'numbers', span: 'page', placement: 'bottom', // floats to a page foot
background: col('ink'), columnGap: mm(8),
padding: { top: mm(5), right: mm(6), bottom: mm(5.5), left: mm(6) },
titleStyle: { ...sans, fontWeight: 700, fontSize: pt(7.5), letterSpacing: pt(1.5),
color: col('ice'), gap: mm(1) },
body: { fontFamily: 'Instrument Sans', fontSize: pt(9), lineHeight: pt(12.5),
textAlign: 'left', hyphenation: false, color: col('ice'), firstLineIndent: pt(0) } };
// The panel's figures are level-4 headings (#### 31), a level the story never uses.
const figures = { level: 4, fontSize: pt(40), lineHeight: pt(40), color: col('ember'),
marginBottom: pt(4) };
// The end mark is a chip of one space, :chip[ ]{style="end"}: an empty box. Its lengths are
// in its own ems: paddingX makes the width, and the height is its font size's band (0.8
// ascent + 0.25 descent). It is ink, like the text it closes, in the story and in the guide.
const endMark = { id: 'end', background: col('ink'), borderWidth: pt(0), borderRadius: pt(0),
fontSize: em(0.62), paddingX: em(0.525), paddingY: em(0), gap: em(0.8) }; // 1.05 em square
设置placement: 'top'后,资料框成为浮动体:它离开正文流,放到下一个空闲的栏顶,正文就一直排到栏底,不会在框放不下的地方留空。数字栏往另一个方向浮动,到页面底部,并横跨两栏;其中的三个数字是四级标题(文章从不用这一级),由breaks="3,5"分配位置,这个参数按子块计数,而不是按行。结束符是一个没有可见文字的行内标签。它的paddingX决定方块的宽度,行内标签的字号决定高度,两者都是行内标签自身字号的1.05 em。
#5 · 写出期号和文章名的书眉
const FOLIO_PT = 8.5; // the folio's size in pt
const LABEL_PT = 7.5; // the label's size in pt
const SQUARE = 2.1; // mm: the lake square's side, the folio's cap height
const label = { ...sans, fontSize: pt(LABEL_PT), letterSpacing: pt(1.3), color: col('muted') };
const folio = { fontFamily: 'Instrument Sans', fontWeight: 700, fontSize: pt(FOLIO_PT),
color: col('ink') };
// A design text's baseline sits 0.8 down its line box, 1.2 × its size (the default lineHeight).
const baseline = (size) => size * 1.2 * 0.8 * 25.4 / 72; // mm from its box's top, size in pt
const HEAD_Y = 12; // mm from the top edge to the folio's box, inside the 22 mm top margin
const LINE = HEAD_Y + baseline(FOLIO_PT); // the heads' one baseline, from the top edge
const pin = (edge, x, y = HEAD_Y) => ({ anchor: { to: 'page', edge },
offset: { x: mm(x), y: mm(y) } }); // in the margin (gotcha: header-paints-over-text)
const sides = [['even', 'left', 1], ['odd', 'right', -1]]; // 1: the outer edge is on the left
const header = { elements: sides.flatMap(([parity, edge, s]) => [
{ kind: 'text', id: `folio-${parity}`, content: '{pageNumber}', ...folio,
placement: pin(`top-${edge}`, s * OUTER) },
{ kind: 'box', id: `square-${parity}`, style: { backgroundColor: col('lake') },
placement: { ...pin(`top-${edge}`, s * (OUTER + 7.5), LINE - SQUARE), // on the line
size: { width: mm(SQUARE), height: mm(SQUARE) } } },
// The smaller label's baseline sits higher in its box (0.34 mm at 7.5 and 8.5 pt), so its
// box goes that much lower: folio, square and label share one baseline at any size.
{ kind: 'text', id: `head-${parity}`, ...label,
content: s > 0 ? '{title} · {subtitle}' : '{chapterTitle}',
placement: pin(`top-${edge}`, s * (OUTER + 11.5), LINE - baseline(LABEL_PT)) },
].map((element) => ({ ...element, parity, pages: 'body' }))) }; // no running heads on openers
const footer = { elements: sides.map(([parity, edge, s]) => ({ kind: 'text', parity,
id: `drop-folio-${parity}`, ...folio, content: '{pageNumber}', pages: 'opener', align: edge,
placement: pin(`bottom-${edge}`, s * OUTER, -11) })) }; // an opener's only folio, at the foot
页眉元素画在页面上,不占空间,所以每一部分都用毫米偏移锚定在页面上边距里。左页写出前置元数据中的杂志名和期号,右页写专题的标题;pages: 'body'让两者都不出现在首页上,首页只在页脚印页码。设计文本的基线位于行框从上往下0.8处,行框高为字号的1.2倍,所以baseline()把7.5 pt的标签比8.5 pt的页码下移0.34 mm,并让方块立在同一条线上。改动任一字号后,三部分仍共用一条基线。
#6 · 下一篇沿用同一个首页
const ART = 126; // mm: the drawing bleeds less far down the page than the photograph
// On its pages, 'lake' turns rust in the opener, the headings, the boxes and the chips.
const guide = { id: 'guide', advancedDesign: opener('ice-art', ART),
palette: { lake: palette.rust } };
首页设计是一个函数,所以野外指南通过标题样式# Five Kinds of Ice {style="guide" kicker="Field guide" …}得到同样的设计,只换了图片和深度。插画向下出血126 mm,而不是160 mm;出处和眉题从depth - TOP起算,其余文字都挂在眉题下,所以它们一起上移34 mm,指南的正文也开始得更高。这个样式的调色板在这几页把lake映射为铁锈色,于是眉题以及所有链接到lake的小标题和框都变成铁锈色,不必给opener()传颜色参数;链接到lake的行内标签也会变成铁锈色,而结束符在两篇里都用墨色。
完整食谱
// ═══ Postext Cookbook · Nº 004 · Magazine feature: photo opener to end mark ═══════
// https://postext.dev/en/cookbook/magazine-feature-opener
// Code: MIT · Text: original (CC BY 4.0) · Photos: Ales Krivec, Hannah Donze (CC0)
// Fonts: Literata, Instrument Serif, Instrument Sans (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// A nature feature from a winter issue. The level-1 heading carries its kicker, standfirst,
// byline and photo credit as attributes, and one opener design lays them out under a bleed
// photograph; the story runs on with a pull quote, a fact box, a photo band, a numbers panel
// and an end mark, and the next item reuses the opener with a drawing in place of the photo.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'magazine-feature-opener';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Every colour below is linked to this palette by id.
const palette = {
ink: '#15191c', // text: a blue-black
lake: '#2d6a7d', // the accent: kickers, crossheads, the quote, the fact box's stripe
ember: '#c8773d', // the panel's figures: 5.2:1 on ink (only 3.4:1 on paper)
rust: '#9a5a2e', // the field guide's accent, swapped in for 'lake' by its heading style
ice: '#dbe8ec', // the type on the dark panel and the drawing's sky
rule: '#c7cdd1', // the drawing's far ridge and air bubbles
muted: '#66707a', // running heads, credits, the colophon
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' } })),
// The engine's defaults link to 'main-color': point it at the accent, so nothing prints blue.
{ id: 'main-color', name: 'lake (defaults)', value: { hex: palette.lake, model: 'hex' } },
];
const TRIM = 225; // page width in mm, shared with the drawing
const INNER = 16; // inner margin in mm
const OUTER = 14; // outer margin in mm: folios and running heads align to it
const LEAD = 13.4; // body leading in pt: the baseline grid
// #region answer: a bleed photo, then the heading's kicker, headline, standfirst, byline and credit
const TOP = 22; // top margin in mm: an opener's container starts here
const sans = { fontFamily: 'Instrument Sans', fontWeight: 600, textTransform: 'uppercase' };
const HEAD = 118; // mm: the headline's measure; the standfirst takes the rest of the line
// Empty padding paints nothing but counts: the story starts on the first grid line at least
// 5 mm under the lower of the headline and the byline, however many lines each one runs to.
const air = { padding: { bottom: mm(5) } };
const at = (id, edge, x, y, width) => ({ anchor: { to: id, edge },
offset: { x: mm(x), y: mm(y) }, ...(width && { size: { width: mm(width) } }) });
const opener = (resourceId, depth) => ({ // depth: how far down the page the picture bleeds
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
常见问题
易错点
位图的印刷尺寸取自分辨率:声明分辨率,不要换算印刷像素
没有分辨率的位图按文档dpi以一个像素对应一个排版像素放置,所以2400 px的照片在150 dpi的页面上宽406 mm。声明文件的实际像素,并给图片设分辨率(bitmap.resolution: 300),或为所有位图设置layout.bitmapResolution:一个ppi值,或用'file'读取文件标明的分辨率。栏宽仍会限制图片。 作为资源的图和表 →
易错点
'top'浮动体默认排在引用页的下一页,除非允许它置于引用页顶
默认情况下浮动体不会排在自己的引用之前,所以在第N页引用的整页宽'top'浮动体会出现在第N+1页的顶部。在资源或其类型的defaultPlacement上设置placement.citingPage: true(或者对全书设置layout.floatsAtCitingPage,自postext 1.25起),它就改为置于第N页顶部,引用处之上的文字移到它下方,前提是它不超过layout.maxTopFraction且引用行仍留在该页。它不会置于章首页或强制分页之后的页面顶部:那时仍排在下一页,而'auto'或'bottom'可以占用引用页的底部。 图的放置 →
沙盒检查 · bitmapTooSmall
图像分辨率低
原因. 某张位图绘制的宽度超过其像素宽度的1.5倍,印刷出来会发虚。
解决. 提供按印刷尺寸约300 dpi的图片,并声明位图的真实宽度和高度。 文档 →
- 图片元素把图片缩放到框内,从不裁切。把JPEG裁成框的比例,这里是225 × 160 mm,否则照片会缩小,页边留出白条。
- 悬挂的引号需要页边。如果修改后引文框落到右栏,引号会填满6 mm的栏间距,碰到左栏的文字:把引文框往前或往后挪一段。
- 文章经过字数调整,结束在第59页、数字栏之上。多出几行就会把结尾挤到单独一页,所以修改后要在两种语言中重新调整字数。
runtMinCharacters: 40避免最后一行只有一个词。断行算法无法避开很短的末行时,引擎会把段落少排一行,收紧词间距,不够时再把字距最多减小0.01 em。修改后,找出排得这么紧的段落,删减或增加几个词来解决;随附的文本在两种语言中都不需要这种修正。
致谢
- 文本
- 原创文字, CC BY 4.0
- 图片
- Clouds mirrored in a mountain lake (the opener photograph) · Ales Krivec · CC0 1.0
- Walk in a thawing forest (the photo band) · Hannah Donze · CC0 1.0
- 字体
- Literata (SIL OFL 1.1) · Instrument Serif (SIL OFL 1.1) · Instrument Sans (SIL OFL 1.1)


