简单来说
一份地方周报的头版和第2版。示例演示怎样让大标题横跨整个版面,并在版面底部放一排简讯。
成品一览
虚构的山谷周报《The Elverdale Courier》的头版和第2页,纸张尺寸246 × 328 mm。哥特体报头夹在天气报眼和价格报眼之间,下方是一粗一细两条线和日期行。头条新闻以横跨两栏的两行大标题开头,字体为56 pt的Libre Franklin Black,接着是斜体副题和一条222 mm宽的照片图带,然后正文分两栏两端对齐,中间一条细栏线。页脚处,四条简讯共用一条浅色底带,每栏一条,各以一个红色行内标签开头。第2页以一面红色栏目旗标开始,包含配有代码绘制插画的大桥报道、右栏顶部的五日天气预报、第二个通页宽标题、读者来信,以及一张每行带条形的选区投票表。
这道食谱解答
- Postext能排三栏或更多栏,或者让文字绕图排吗?
- 怎样在页面中间排一个横跨两栏的框,比如三格并列的“数字一览”面板?
- 怎样控制图的位置:页面顶部、横跨两栏、就放在这里,还是放在边栏里?
- 怎样让章标题横跨页面,下面的正文分两栏排?
简短回答
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 · 新闻纸、油墨和一种红
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)。唯一的红色#a6192e用于栏目旗标、眉题、行内标签和“赞成”条形。每种颜色都通过paletteId关联到调色板中的条目。main-color指向油墨色,所以粗体、斜体、第2页的两处引用以及配置中所有保留默认值的地方都印成油墨色;若保留它原来的值,这些地方会印成默认的蓝色#295AA3。
#2 · 报头就是头版的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标题样式,这个样式用标题文字和它的七个属性(issue、area、outlook、temps、since、day和price)填充报头;日期取自前置元数据中的publishDate。一个七条网格线深(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
标题只有作为首页设计时才能横跨两栏,而首页设计会开新页。如果把span: 'page'放在选区报道的H2上而不是它的框上,这篇报道会移到第三页。无边框、带span="page"的框可以从页面中间开始。在第2页,各栏在它上方齐平截断,在它下方继续。框里放三种标题样式之一(56、30或22 pt)的H2、斜体副题,头版上还有照片。它的marginBottom为半行,使各栏从下一条网格线开始,在第2页即副题下方3.4 mm。用默认外边距时间隔为7.8 mm,读者来信会排到第三页。
#4 · 四栏的简讯带是一个框
这一步的代码见上面的简短回答。两页的正文都排两栏(版式类型)。简讯只在第1页底部需要四栏,还带标题和底色,所以放进一个框里,这里是一个通页宽的框,内含一组:::columns。breaks按组内的块计数,一条简讯一个块,所以第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页的大桥插画旁边就排着正文(第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横条上的一面红色旗标,挂在一个两条网格线深的空框上。页码行是锚定在页面顶边下方6 mm处的页眉,偶数页和奇数页各有一个版本。头版的样式清空页眉,所以报头上方不印页码行。
完整食谱
// ═══ 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起),它就改为置于第N页顶部,引用处之上的文字移到它下方,前提是它不超过layout.maxTopFraction且引用行仍留在该页。它不会置于章首页或强制分页之后的页面顶部:那时仍排在下一页,而'auto'或'bottom'可以占用引用页的底部。 图的放置 →
易错点
位图的印刷尺寸取自分辨率:声明分辨率,不要换算印刷像素
没有分辨率的位图按文档dpi以一个像素对应一个排版像素放置,所以2400 px的照片在150 dpi的页面上宽406 mm。声明文件的实际像素,并给图片设分辨率(bitmap.resolution: 300),或为所有位图设置layout.bitmapResolution:一个ppi值,或用'file'读取文件标明的分辨率。栏宽仍会限制图片。 作为资源的图和表 →
- 给照片设
placement: { position: 'top', span: 'page' },它就会离开第1页,单独排在第2页。第1页的报道随之在简讯条上方92 mm处结束,栏目移到第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)


