简单来说
一本小型展览图录,收了三幅《堂吉诃德》的旧版画。每段说明印在左页,对面的右页整页印着那幅画。
成品一览
一本小型图录,用于一场小型展室展览,展出Gustave Doré《Don Quixote》(巴黎,1863)中的三幅木刻版画,页面为230 × 280 mm。封面在暖黑底上用88 pt的Libre Bodoni排出DORÉ,上方是风车版画一块带框的局部。每个条目从左页开始:深褐色的图录编号排在斜体标题旁,外侧栏是展品信息,然后是一段三行首字下沉的导语和评述。评述的第一句引用图版,图版排在对面右页的开头,居中,并缩小到图版、题注和出处正好填满版心,高215 mm。最后一页是展品清单,每行第一格是缩略图,并列出每幅图版所在的页码。
这道食谱解答
- 怎样做艺术图录:左页放条目,对面右页放图版?
- 怎样控制图的位置:页面顶部、横跨两栏、就放在这里,还是放在边栏里?
- 怎样在表格单元格里放图片或图标?
- 怎样给章首页加作者行、提要或带首字下沉的导语?
简短回答
// Each entry breaks to a verso and cites its plate in the commentary's first sentence; a 'top'
// float never lands on its citing page (gotcha: top-float-next-page), so it opens the recto.
const entryLevel = () => ({
level: 1, span: 'page', numberingTemplate: '{1}', // {number} in the opener: Cat. 1, 2, 3
breakBefore: { enabled: true, parity: 'even' }, // an entry opens a verso, facing its plate
marginBottom: pt(LEAD), advancedDesign: entryOpener(),
dropCap: { lines: 3, fontFamily: DISPLAY, color: col('sepia'), gap: mm(1.6) }, // the lead's
});
const plateType = {
id: 'plate', name: 'Cat.', shortLabel: 'Cat.', captionPrefix: 'Cat.', // 'Cat. 1. …'
numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal',
// A plate taller than the recto's text block is scaled, proportions kept, until plate, caption
// and credit line fit it; the caption takes the plate's width, and both are centred.
defaultPlacement: { position: 'top', span: 'page', align: 'center',
shrink: 'page', minScale: 0.5, captionMeasure: 'body' },
};
// Under the plate (pt): a caption and a credit line, and their gaps.
const CAPTION = { size: 8.5, gap: 6, note: 7.2, noteGap: 1.5 };
const plate = ({ id, file, caption, altText }, [pxW, pxH]) => ({
id, typeId: 'plate', kind: 'bitmap', caption, note: CREDIT, altText,
// The print master's pixels, about 283 dpi at this size (gotcha: bitmap-print-size).
bitmap: { fileId: file, format: 'jpeg', width: pxW, height: pxH }, createdAt: 0, updatedAt: 0,
});
用料
- 功能
- 图的放置从右页开始的章决定图位置的引用自定义资源类型编号题注题注样式来源与出处行作为资源的图和表表格单元格中的图片设计过的章首页通栏章首色带正文段落的首字下沉页面设计中的文字、线条和框页面设计中的图片标题属性标题样式对称页边距在Canvas上绘制页面段落样式
- 类型
- Ibarra Real Nova, Libre Bodoni, Sofia Sans Condensed(SIL OFL 1.1)
- 素材
library-835.jpgvigil-835.jpgwindmills-835.jpgwindmills-detail-540.jpg- Cat. 1, Don Quixote in His Library (Part I, ch. I), wood engraving by Héliodore Pisan after Gustave Doré, 1863; scan from Wikimedia Commons, reduced to 835 px wide (Gustave Doré · Héliodore Pisan, 公有领域)
- Cat. 2, The Vigil of Arms (Part I, ch. III), wood engraving by Héliodore Pisan after Gustave Doré, 1863; scan from Wikimedia Commons, reduced to 835 px wide (Gustave Doré · Héliodore Pisan, 公有领域)
- Cat. 3, The Adventure of the Windmills (Part I, ch. VIII), wood engraving by Héliodore Pisan after Gustave Doré, 1863; scan from Wikimedia Commons, reduced to 835 px wide (Gustave Doré · Héliodore Pisan, 公有领域)
- The cover’s detail of Cat. 3: a 1,100-px square cut from the same scan and reduced to 540 px (Gustave Doré · Héliodore Pisan, 公有领域)
做法
#1 · 图版等到对面那一页
代码就是上面的简短回答。每个条目都换到偶数页开始,而top浮动体从不落在引用它的那一页,所以评述第一句引用的图版会跳过左页,排在对面右页的开头。图版类型的defaultPlacement设了shrink: 'page':按整个版宽,图版会有242 mm高,超出右页版心的容量,所以Postext按原比例把它缩小,直到图版、题注和出处放进浮动间距之上的横带(位置)。minScale: 0.5允许图版缩到原宽的一半;这里每幅图版都保留约十分之九的宽度。captionMeasure: 'body'让题注和出处与图版同宽,align: 'center'把两者一起在页面上居中。
#2 · 条目开头来自它的标题
const [KICKER, NUMERAL] = [8.5, { size: 80, y: 7 }]; // pt: labels; the numeral, y in mm
const TITLE = { size: 30, lineHeight: 1.08 }; // pt; a multiple of the size
const HEAD_RULE = NUMERAL.y + NUMERAL.size * PT + 3; // mm: the hairline under the numeral
// mm: the lead, the entry's first paragraph, 5 mm under the hairline on the next grid line;
// the opener ends a line above it (the level's marginBottom), and the tombstone faces it.
const LEAD_Y = Math.ceil((HEAD_RULE + 5) / PT / LEAD) * LEAD * PT;
const [LEADIN, TOMB] = [{ size: 13.5, lead: 19 }, { size: 8.5, lead: 12.5 }]; // pt
const BASE = 0.8; // a line's first baseline stands 0.8 down its line box
// em: Libre Bodoni's capitals, and its figures, which stop short of them ('1': 0.716)
const [CAP_HEIGHT, FIGURE_HEIGHT] = [0.754, 0.716];
const inkTop = (size, lineHeight, height) => (BASE * lineHeight - height) * size; // pt to the ink
// The title's capitals level with the numeral's figures: 1.2 mm below the numeral's top.
const TITLE_Y = NUMERAL.y + (inkTop(NUMERAL.size, 1, FIGURE_HEIGHT)
- inkTop(TITLE.size, TITLE.lineHeight, CAP_HEIGHT)) * PT;
// Entries open on versos, whose outer column is on the left: the side column is at x = 0.
const head = (label, numeral) => [
text('label', label, LABEL, KICKER, 'sepia', at('container', 'top-left', 0, 0), caps(KICKER)),
text('numeral', numeral, DISPLAY, NUMERAL.size, 'sepia',
at('container', 'top-left', 0, NUMERAL.y, SIDE), { lineHeight: 1 }),
text('title', '{titleText}', DISPLAY, TITLE.size, 'ink', at('container', 'top-left', MAIN_X,
TITLE_Y, MAIN), { italic: true, lineHeight: TITLE.lineHeight }),
{ kind: 'rule', id: 'head-rule', direction: 'horizontal', thickness: pt(0.5), color: col('rule'),
placement: at('container', 'top-left', 0, HEAD_RULE, 'fill') },
];
const entryOpener = () => ({ enabled: true, minHeight: mm(LEAD_Y - LEAD * PT),
slot: { elements: [...head('Cat.', '{number}'),
text('chapter', '{attr.chapter}', LABEL, KICKER, 'sepia',
at('container', 'top-left', MAIN_X, 0, MAIN), caps(KICKER)),
// Baseline on the lead's; the attribute's \n breaks give its three lines.
text('tombstone', '{attr.tombstone}', LABEL, TOMB.size, 'muted',
at('container', 'top-left', 0, LEAD_Y + BASE * (LEADIN.lead - TOMB.lead) * PT, SIDE - 6),
{ lineHeight: TOMB.lead / TOMB.size, reserve: false }), // beside the lead: no room of its own
] } });
每个#标题都把章和展品信息作为属性带着,由章首页的设计槽位画出来。大号数字就是标题自己的{number},来自numberingTemplate: '{1}';每个条目只有一幅图版,所以它和图版的Cat.计数器同步,依次为1、2、3。导语是条目的第一段,放在13.5 pt的:::paragraphs{style="lead"}组里,由这一级别的dropCap以三行高的深褐色首字母开头:首字母的顶部与第一行大写字母的顶部齐平,底部落在第三条基线上,两者的大写字母高度都从字体中量得(首字下沉)。导语齐左排:在这个字号下每行只有寥寥几个词,两端对齐会把词距撑得超过评述所允许的1.5倍。minHeight让章首页结束在LEAD_Y上方一行处,LEAD_Y就是导语开始的那条网格线;展品信息与导语的第一行相对,自身不占空间(reserve: false);导语下的:::space空出一行,评述从下一行不缩进地开始。TITLE_Y把标题排得比数字低1.2 mm,让它的大写字母与数字对齐:在Libre Bodoni里,数字高0.716 em,大写字母高0.754 em。
#3 · 声明母版,绘制较小的副本
// plate() sizes each plate from its master, the Commons scan at 2,400 px tall (MASTER_PX);
// the canvas draws the registered 835-px copy (the block's width on a 1,000-px page) in that box.
async function scan(file) {
const res = await fetch(asset(file));
if (!res.ok) throw new Error(`Scan not found (${res.status}): ${file}`);
return createImageBitmap(await res.blob());
}
async function loadPlates() {
const [detail, ...scans] = await Promise.all([DETAIL, ...PLATES.map((p) => p.file)].map(scan));
const resources = [checklist(PLATES), picture('cover-detail', onPaper(detail),
'Detail of Cat. 3: the knight and his horse caught on the sail.')];
for (const [i, p] of PLATES.entries()) {
registerResourceImage(p.file, onPaper(scans[i]));
resources.push(plate(p, MASTER_PX[p.id]), // and a thumbnail: its own small file and size
picture(`${p.id}-thumb`, onPaper(await resized(scans[i], THUMB_PX)), p.altText));
}
return resources;
}
Postext按位图声明的像素和文档的dpi确定它的尺寸,印出的宽度绝不超过这些像素允许的范围。plate()声明每幅图版的母版,也就是缩到2,400 px高的Commons扫描件:Cat. 1为1,900 × 2,400 px,在page.dpi: 150下最宽可达322 mm。所以尺寸由版心决定,高215 mm,在这个高度下2,400 px约合283 dpi。如果用默认的300 dpi,图版宽到161 mm就会停住。Canvas会把注册的任何图片画进这个框,所以示例下载assets/里的三份835 px副本,共0.97 MB,而母版是5.8 MB。如果改用2,400 px的母版绘制,天空会出现摩尔纹条带,截图里的图片也会增加约0.3 MB,超出排版食谱1.4 MB的上限。
#4 · 用标题样式做封面
const DETAIL = 'windmills-detail-540.jpg'; // a square cut from Cat. 3, at its size on screen
const FRAME = { w: 124, y: 40, pad: 3.5 }; // mm: the picture, its top, the hairline's inset
const FRAME_X = (TRIM.w - FRAME.w) / 2;
const NAME = { size: 88, track: 8, y: 176 }; // pt, pt, mm
const centred = (id, content, family, size, color, y, more) => text(id, content, family,
size, color, at('page', 'top', 0, y, 'fill'), { align: 'center', ...more });
const coverStyle = () => ({
id: 'cover', numbered: false, header: { elements: [] }, footer: { elements: [] },
advancedDesign: { enabled: true, slot: { elements: [ // painted in this order
{ kind: 'box', id: 'night', style: { backgroundColor: col('night') },
placement: { ...at('bleed', 'top-left', 0, 0), size: { width: 'fill', height: 'fill' } } },
{ kind: 'box', id: 'frame', style: { borderColor: col('gilt'), borderWidth: pt(0.5) },
placement: { ...at('page', 'top-left', FRAME_X - FRAME.pad, FRAME.y - FRAME.pad),
size: { width: mm(FRAME.w + 2 * FRAME.pad), height: mm(FRAME.w + 2 * FRAME.pad) } } },
{ kind: 'image', id: 'detail', resourceId: 'cover-detail',
placement: at('page', 'top-left', FRAME_X, FRAME.y, FRAME.w) },
centred('kicker', '{attr.kicker}', LABEL, 8.5, 'gilt', 18, caps(8.5)),
// Tracked capitals centre on their letters: the tracking after the É is left out.
centred('name', '{titleText}', DISPLAY, NAME.size, 'paper', NAME.y, { lineHeight: 1,
textTransform: 'uppercase', letterSpacing: pt(NAME.track) }),
centred('subtitle', '{attr.subtitle}', DISPLAY, 18, 'paper', NAME.y + NAME.size * PT + 4,
{ italic: true }),
centred('foot', '{attr.foot}', LABEL, 8.5, 'gilt', 250, caps(8.5)),
] } },
});
封面是第一个标题# Doré {style="cover" …},由一个不带页码的样式画出。它的图片元素绘制windmills-detail-540.jpg,这是一个注册为资源但没有段落引用的文件,所以没有编号,也没有题注。这个文件是从风车扫描件上截下的1,100 px见方的一块,缩到540 px,正好是它在1,000 px宽页面上的宽度。名字设了8 pt字距,居中时不计最后一个字母后面的那一段,所以四个大写字母不用偏移就落在页面中线上。
#5 · 展品清单单元格里的缩略图
const THUMB_PX = 300; // px wide: 25 mm at 300 dpi, about the width the cell prints it
// The entries' head, label and numeral from attributes; the level gives span, break and margin.
const checklistStyle = () => ({ id: 'checklist', numbered: false, dropCap: false, // no initial
advancedDesign: { enabled: true, slot: { elements: head('{attr.kicker}', '{attr.range}') } } });
const cell = (content, more) => ({ content, verticalAlign: 'middle', ...more });
const checklist = (plates) => ({
id: 'checklist', typeId: 'list', kind: 'table', placement: { position: 'here' },
altText: 'Checklist of the three works with thumbnails, titles, chapters and pages.',
table: { model: { headerRowCount: 1, columnWidths: [26, 9, 70, 11], rows: [
['', 'Cat.', 'Work and chapter', 'Page'].map((label, i) =>
cell(label, { isHeader: true, align: i === 3 ? 'right' : 'left' })),
...plates.map((p, i) => [
{ content: '', image: { resourceId: `${p.id}-thumb` } },
cell(String(i + 1)), cell(`*${p.caption}*. ${p.illustrates}`),
cell(String(platePage(i + 1)), { align: 'right' }),
]),
] } },
createdAt: 0, updatedAt: 0,
});
// The cover is page 1 and entry n opens page 2n, so its plate prints on page 2n + 1.
const platePage = (n) => 2 * n + 1;
const listType = { id: 'list', name: 'List', shortLabel: 'List', captionPrefix: '', // no caption
numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal' };
单元格的image把位图资源缩放到单元格的内宽,这里是23 mm。每张缩略图都是一份单独的300 px副本,按这个尺寸声明,而不是在绘制时把835 px的图版缩小。表格没有题注文字,它的类型题注前缀为空,所以不画题注。清单样式只设置numbered: false和它的版面设计,通栏、换到左页和下边距都从第1级继承。
#6 · 条目超出一页时停下
const astray = doc.pages.find((pg) => pg.role !== 'opener' && !pg.floats?.length);
if (astray) { // text run past its verso, or the blank page that follows it
const error = new Error(`Page ${astray.pageLabel} holds no plate: shorten the entry before it.`);
kitFail(error); // the viewer's bar says why
throw error;
}
条目排到左页之外时,仍会把它的图版送到下一页。评述的剩余部分接在图版后面,再加一张空白页让下一个条目落在左页,于是后面每幅图版都比清单上给出的页码晚两页。这项检查在第一个既不是章首页、也没有图版的页面处停止构建,并在查看器的工具栏里显示该页的页码。
完整食谱
// ═══ Postext Cookbook · Nº 034 · Catalogue entries facing their plates ══════════════
// https://postext.dev/en/cookbook/catalogue-facing-plates
// Code: MIT · Text: original (CC BY 4.0), Ormsby 1885 (PD) · Plates: Doré and Pisan, 1863 (PD)
// Fonts: Ibarra Real Nova, Libre Bodoni, Sofia Sans Condensed (OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en')
const RECIPE = 'catalogue-facing-plates';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
ink: '#1b1918', paper: '#faf7f1', night: '#2a2724', // text; the page and plates; the cover
sepia: '#8a6a45', gilt: '#c9ad86', // the accent on paper (4.6:1) and on the night (6.9:1)
rule: '#cfc6b8', muted: '#6c665e', // hairlines; tombstones, credit lines, folios
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the id.
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: 'sepia (defaults)', value: { hex: palette.sepia, model: 'hex' } },
];
const [TEXT, DISPLAY, LABEL] = ['Ibarra Real Nova', 'Libre Bodoni', 'Sofia Sans Condensed'];
const PT = 25.4 / 72; // mm per point
const [SIZE, LEAD, LINES] = [11.5, 16, 41]; // body pt, leading pt; 41 lines make the text block
const TRIM = { w: 230, h: 280 }; // mm: a catalogue trim
const [TOP, INNER, OUTER] = [24, 20, 18]; // margins, mm
const BLOCK_W = TRIM.w - INNER - OUTER; // 192 mm: the text block, and the widest plate
const BLOCK_H = LINES * LEAD * PT; // 231.4 mm
const [SIDE_PC, GUTTER] = [34, 7]; // the outer column: 65.3 mm for numeral and tombstone; mm
const SIDE = (BLOCK_W * SIDE_PC) / 100;
const MAIN_X = SIDE + GUTTER; // mm from the block's outer edge to the text column
const MAIN = BLOCK_W - MAIN_X; // 119.7 mm: the measure, about 71 characters
// #region answer: a Plate type that floats to the head of the facing recto, sized to fill it
// Each entry breaks to a verso and cites its plate in the commentary's first sentence; a 'top'
// float never lands on its citing page (gotcha: top-float-next-page), so it opens the recto.
const entryLevel = () => ({
level: 1, span: 'page', numberingTemplate: '{1}', // {number} in the opener: Cat. 1, 2, 3
breakBefore: { enabled: true, parity: 'even' }, // an entry opens a verso, facing its plate
marginBottom: pt(LEAD), advancedDesign: entryOpener(),
dropCap: { lines: 3, fontFamily: DISPLAY, color: col('sepia'), gap: mm(1.6) }, // the lead's
});
const plateType = {
id: 'plate', name: 'Cat.', shortLabel: 'Cat.', captionPrefix: 'Cat.', // 'Cat. 1. …'
numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal',
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#在图版下方留白
用宽度比例让浮动体本身变窄:设为版心宽度的78%,每幅图版约188 mm高并居中,出处下方的版心留出约27 mm空白,也就不需要再缩小。
- defaultPlacement: { position: 'top', span: 'page', align: 'center',
- shrink: 'page', minScale: 0.5, captionMeasure: 'body' },
+ defaultPlacement: { position: 'top', span: 'page', align: 'center', width: 0.78 },#把图排在外侧栏
如果要让图和旁注堆叠在只放浮动体的外侧栏里,紧挨引用它们的段落,请看带边栏的教科书。
常见问题
易错点
'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'读取文件标明的分辨率。栏宽仍会限制图片。 作为资源的图和表 →
沙盒检查 · bitmapTooSmall
图像分辨率低
原因. 某张位图绘制的宽度超过其像素宽度的1.5倍,印刷出来会发虚。
解决. 提供按印刷尺寸约300 dpi的图片,并声明位图的真实宽度和高度。 文档 →
致谢
- 文本
- The catalogue entries, captions, tombstones and checklist · Postext Cookbook · CC BY 4.0
- Quotations from Don Quixote in John Ormsby’s English translation (1885) · Miguel de Cervantes · John Ormsby · 公有领域
- 图片
- Cat. 1, Don Quixote in His Library (Part I, ch. I), wood engraving by Héliodore Pisan after Gustave Doré, 1863; scan from Wikimedia Commons, reduced to 835 px wide · Gustave Doré · Héliodore Pisan · 公有领域
- Cat. 2, The Vigil of Arms (Part I, ch. III), wood engraving by Héliodore Pisan after Gustave Doré, 1863; scan from Wikimedia Commons, reduced to 835 px wide · Gustave Doré · Héliodore Pisan · 公有领域
- Cat. 3, The Adventure of the Windmills (Part I, ch. VIII), wood engraving by Héliodore Pisan after Gustave Doré, 1863; scan from Wikimedia Commons, reduced to 835 px wide · Gustave Doré · Héliodore Pisan · 公有领域
- The cover’s detail of Cat. 3: a 1,100-px square cut from the same scan and reduced to 540 px · Gustave Doré · Héliodore Pisan · 公有领域
- 字体
- Ibarra Real Nova (SIL OFL 1.1) · Libre Bodoni (SIL OFL 1.1) · Sofia Sans Condensed (SIL OFL 1.1)


