跳到主要内容
食谱编号44

排版食谱 · 第2章 · 字体与文字

校勘本:行号与按行号编排的注释

按1645年文本排弥尔顿的《Lycidas》:lineNumbers给诗行计数,把每第五行的行号印在侧栏里,每条注释以其行号开头,行号排成行内标签。

本页内容
类型
诗歌
输出
Canvas
难度
高级
Postext
已用Postext 1.65.0测试
需要≥ 1.25.0
许可证
更新于2026年10月10日
代码MIT · 文本CC BY 4.0
  • 英文样例:尚无中文版本
  • 成品尺寸138 × 216 mm
  • 一栏半, 栏间距4 mm
  • Linden Hill 10.5/14.5
  • Imbue
  • Libre Franklin
  • 9页
  • 难度
  • Postext 1.57.1
  • 排版用时71 ms
  • 168行代码

简单来说

弥尔顿一首长诗的校注本。每隔五行在页边标一个行号,诗后的注释用行号指明所解释的诗句。

成品一览

Lycidas是弥尔顿悼念Edward King的挽歌,这里按1645年《Poems》的文本和拼写,排成一本138 × 216 mm的小型校勘本。第一页以一枝月桂开篇,标题是Imbue的瘦高大写字母,下面是弥尔顿1645年加上的题记。随后是193行诗,每行诗占一行,诗节之间空一行,短行缩进。每第五行在切口侧6 mm宽的栏里用月桂绿标出行号:右页在诗行右侧,左页在诗行左侧。诗行里不带注释标记。注释排在诗后的两页,每条以所在行的行号开头,用与页边行号相同的绿色Libre Franklin。

这道食谱解答

  • 怎样在诗的页边每隔五行标一个行号,并让注释对应这些行号?
  • 怎样排诗歌:每句一行,诗节间留空,折行悬挂缩进,不断词?
  • 脚注怎么做?
  • 怎样做一栏半版式,一个宽的正文栏加一个窄的侧栏?
  • 空行不起作用时,怎样在两个块之间加额外的垂直间距?

简短回答

script.js · 第30–43行在完整代码中
// The poem is one :::verse block, written as 1645 prints it: a line of verse a line, a blank
// line between verse paragraphs and two spaces before a short line. lineNumbers counts its
// lines of verse (a line that turned over would still count once) and prints the multiples
// of five beside their lines, on their baselines. position 'side' puts them in the side
// column of the one-and-a-half layout, flush with its edge next to the verse.
const lineNumbers = {
  enabled: true,
  count: 'verse', // the lines of :::verse poems; the notes are prose and not counted
  interval: 5,
  restart: 'document', // one count through the poem
  position: 'side',
  fontFamily: LABEL, fontSize: pt(7.5), color: col('laurel'),
};
// Hook-up: lineNumbers in the config; the Markdown goes to buildDocument as it is written.

用料

类型
Linden Hill, Imbue, Libre Franklin(SIL OFL 1.1)
素材
  • laurel-1040.jpg
  • The sprig of bay laurel on the first page, a watercolour (Generated With Diffusion Models, 原创)

做法

#1 · 数诗行

这一步的代码见上文的简短回答。lineNumbers给诗的诗行计数,把每第五行的行号印在该行旁边、该行的基线上,用7.5 pt、月桂绿的Libre Franklin(行号)。count: 'verse'只数:::verse诗的诗行,所以关于文本的说明和诗后的注释都不编号;一行诗即使长得超出行长,也仍然只算一行:它的转行部分不带行号。restart: 'document'让整首诗只用一套计数。行号画在排版已经排好的行旁边,所以从不移动任何一行。

#2 · 一条六毫米宽的窄栏

script.js · 第47–63行在完整代码中
const PT = 25.4 / 72; // mm in a point
const [TRIM_W, TRIM_H] = [138, 216]; // mm
const [TOP, INNER] = [21, 20]; // mm
const LINES = 34; // lines of verse to a page
const BOTTOM = TRIM_H - TOP - LINES * LEAD * PT; // 21.08 mm
const [MEASURE, GUTTER, CHANNEL] = [80, 4, 6]; // mm: the longest line of Lycidas is 78.1 mm
const OUTER = TRIM_W - INNER - MEASURE - GUTTER - CHANNEL; // 28 mm beyond the numbers
const layout = {
  layoutType: 'oneAndHalf',
  sideColumnRole: 'floats', // the side column takes the numbers, never text
  sideColumnSide: 'outer', // right of the verse on a recto, left of it on a verso
  // 6 of 90 mm. The zero is Libre Franklin's widest figure, so '100' (4.9 mm) is the widest number.
  sideColumnPercent: (CHANNEL / (MEASURE + GUTTER + CHANNEL)) * 100,
  gutterWidth: mm(GUTTER),
};
const page = { sizePreset: 'custom', width: mm(TRIM_W), height: mm(TRIM_H), dpi: 150,
  margins: { top: mm(TOP), bottom: mm(BOTTOM), left: mm(INNER), right: mm(OUTER), mirror: true } };

设置sideColumnRole: 'floats'后,oneAndHalf版面的窄栏永远不排正文(版面类型),position: 'side'把行号排进这一栏,贴齐它靠诗行的一边;4 mm的栏间距就是诗行与行号之间的距离。sideColumnPercent是版心宽度的一个比例,所以CodePen示例用毫米换算:90 mm中的6 mm,足够放下最宽的行号。Libre Franklin的数字是比例宽度的,7.5 pt时0最宽(1.8 mm,1是1.2 mm),所以100宽4.9 mm,是这首诗里最宽的行号;180和190是4.8 mm。'outer'随对称页边距而变,所以行号在右页位于诗行右侧,左对齐;在左页位于左侧,右对齐:两种页面上,行号的起点或终点与诗行的距离都相同。诗行栏宽80 mm,比最长的第31行宽1.9 mm,所以没有哪一行会转行。

#3 · 整首诗是一个:::verse块

script.js · 第67–72行在完整代码中
// A blank line between verse paragraphs leaves one line of the grid (stanzaSpace, 1). Two
// leading spaces set a short line in 2 em (indentStep, 1 em a space here, against the default
// half em). The verse is ragged, like all the text here; a line too long for the measure would
// turn over and hang 2 em past its own start, but none does at 80 mm.
const verse = { indentStep: em(1) };
const verseStyles = [{ id: 'verse', hangingIndent: em(2) }];

:::verse块按书写的原样保留诗:Markdown的每一行是一行诗,诗节之间空一行,行首的空格就是缩进(:::verse)。围栏上写明诗行样式和align=start,让诗与页边齐平,而不是按最长的一行居中。诗节之间留出网格的一行空行(stanzaSpace,一行)。弥尔顿的十四个短行(第4行即其一)以两个空格开头,indentStep: em(1)让它们缩进2 em。诗节间距在页首会被丢弃,所以第2页从版心顶部的第15行开始,第14行与第15行之间的诗节分隔看不出来(见常见问题)。

#4 · 月桂、标题和题记

script.js · 第76–101行在完整代码中
const OPENER_LINES = 20; // of the page's 34: the first verse paragraph, 14 lines, takes the rest
const at = (id, edge, y) => ({ anchor: { to: id, edge }, offset: { x: mm(0), y: mm(y) } });
const title = (size, tracking, placement) => ({ kind: 'text', id: 'title', content: '{titleText}',
  fontFamily: DISPLAY, fontWeight: 300, fontSize: pt(size), lineHeight: 1,
  letterSpacing: pt(tracking), textTransform: 'uppercase', color: col('ink'), placement });
const opener = { enabled: true, minHeight: pt(OPENER_LINES * LEAD), slot: { elements: [
  // The laurel ends above the kicker, so the depth comes from the texts: kicker, title and
  // headnote reach down 20 lines. minHeight is a floor at the same depth, so a shorter
  // headnote leaves the verse on line 21.
  { kind: 'image', id: 'laurel', resourceId: 'laurel',
    placement: { anchor: { to: 'page', edge: 'top-right' }, size: { width: mm(104) } } },
  { kind: 'text', id: 'kicker', content: '{author}', fontFamily: LABEL, fontWeight: 500,
    fontSize: pt(8), letterSpacing: pt(1.6), textTransform: 'uppercase', color: col('laurel'),
    placement: at('container', 'top-left', 50) },
  title(66, 2, at('#kicker', 'below', 1)),
  // # Lycidas {headnote="In this Monody …"}: the whole headnote in italic, ragged; at
  // 64 mm no word stands alone.
  { kind: 'text', id: 'headnote', content: '{attr.headnote}', fontFamily: TEXT, italic: true,
    fontSize: pt(9.5), lineHeight: 13 / 9.5, color: col('ink'), align: 'left',
    placement: { ...at('#title', 'below', 3), size: { width: mm(64) } } },
] } };
// The poem opens on a recto. Its design stays in the column, and the laurel, anchored to the
// page's corner, is painted above the text block all the same. With the default
// marginBottom the verse would start on line 22 and send line 14 to page 2.
const poem = { level: 1, breakBefore: { enabled: true, parity: 'odd' },
  advancedDesign: opener, marginBottom: pt(0) };

一级标题印出的是版面设计,而不是标题本身的文字(通栏与高级设计)。{author}来自前置元数据,题记来自标题行上的一个属性,# Lycidas {headnote="In this Monody …"}(标题属性)。月桂的下缘在眉题之上,所以开篇的深度取决于其下的文字:眉题位于版心顶部以下50 mm,标题和四行题记一直延伸到本页34行中的第20行,第一个诗节14行,占满其余部分。minHeight是同一深度的下限:把题记删成三行,诗行仍从第21行开始,而没有这个下限,它会上移到第20行。marginBottom: pt(0)让标题的默认外边距不进入这段间距;若保留它,诗行会从第22行开始,把第14行推到第2页。设计留在栏内,而锚定在页面右上角的月桂照样从切边画起:留在栏内的设计只会在栏的底端被裁掉。

#5 · 按行号编排的注释

script.js · 第105–124行在完整代码中
const NOTE = 8.6; // pt: the notes, and the note on the text
const noteStyles = [
  { id: 'textnote', fontSize: pt(NOTE), lineHeight: pt(NOTE * 1.33) },
  // The note on the text ends on the grid, 2.4 mm below its last line; half a line more
  // leaves one blank line before the first note.
  { id: 'note', fontSize: pt(NOTE), lineHeight: pt(NOTE * 1.33), hangingIndent: em(1.6),
    marginTop: pt(LEAD / 2) },
  { id: 'colophon', fontFamily: LABEL, fontSize: pt(7), lineHeight: pt(9.5), color: col('muted'),
    marginTop: pt(LEAD) },
];
// :chip[8]{style="line"}: Linden Hill has no bold, so the number changes face and colour.
// The chip has no fill, outline or side padding, so nothing is drawn around the number.
const chipStyles = [{ id: 'line', backgroundEnabled: false, borderWidth: pt(0), paddingX: pt(0),
  fontFamily: LABEL, fontSize: em(0.9), color: col('laurel') }];
// # Notes {style="notes"} opens the next page under the title's capitals, smaller. A heading
// style keeps the level's break unless it sets its own (gotcha: style-inherits-break). Its
// design stays in the column too, so the title lines up with the notes on either page.
const notesHead = { id: 'notes', breakBefore: { enabled: true, parity: 'any' },
  advancedDesign: { enabled: true,
    slot: { elements: [title(30, 1, at('container', 'top-left', 0))] } } };

注释按行号编排,所以诗行里不带注释标记;注释作为评注排在诗后,不占诗页的行。每条注释以所在行的行号开头,写作:chip[8]{style="line"},然后是斜体的被释词语和一个右方括号。这个行内标签没有填充、描边和左右内边距,所以只改变字体和颜色:7.7 pt、月桂绿的Libre Franklin(标签样式)。Linden Hill没有粗体,所以行号靠换一种字体来区分。注释样式让首行之后的每行缩进1.6 em,使左侧的行号清晰可辨;注释与诗行一样齐左排。# Notes {style="notes"}另起到第8页,标题用开篇页的大写字母,30 pt。

Page 8: each note opens on the green number of its line; the verse on pages 1 to 7 carries no markers.

#6 · 按奇偶页区分的书眉

script.js · 第128–149行在完整代码中
const HEAD = 13; // mm from the trim to the running heads' baseline
// A design text's first baseline sits 0.8 of a line below the top of its box: 0.96 em at the
// default lineHeight of 1.2, which the running heads keep.
const BASE = 1.2 * 0.8;
const head = (id, parity, content, x, size = 7.5, extra = {}) => ({ kind: 'text', id, parity,
  content, pages: 'body', fontFamily: LABEL, fontWeight: 500, fontSize: pt(size),
  letterSpacing: pt(1.3), textTransform: 'uppercase', color: col('muted'), ...extra,
  placement: { anchor: { to: 'page', edge: parity === 'even' ? 'top-left' : 'top-right' },
    offset: { x: mm(x), y: mm(HEAD - BASE * size * PT) } } });
const folio = { fontFamily: TEXT, fontWeight: 400, letterSpacing: pt(0), color: col('ink') };
const header = { elements: [
  head('verso-folio', 'even', '{pageNumber}', OUTER, 10, folio),
  head('verso-head', 'even', '{author}', OUTER + 9),
  head('recto-head', 'odd', '{chapterTitle}', -(OUTER + 9)), // LYCIDAS, then NOTES
  head('recto-folio', 'odd', '{pageNumber}', -OUTER, 10, folio),
] };
// The two openers carry their folio at the foot instead, at the outer edge of the text block.
const drop = (parity, edge, x) => ({ ...head(`drop-${parity}`, parity, '{pageNumber}', 0, 10,
  folio), pages: 'opener', placement: { anchor: { to: 'page', edge },
  offset: { x: mm(x), y: mm(-12) } } });
const footer = { elements: [drop('odd', 'bottom-right', -OUTER),
  drop('even', 'bottom-left', OUTER)] };

每个元素都锚定在页面上,并用parity和pages: 'body'过滤(文本元素)。左页印作者,右页印{chapterTitle},诗页上是LYCIDAS,注释页上是NOTES,因为注释以一个独立的标题开头。页码位于版心的外侧边缘;两个开篇页,即第1页和第8页,页码改排在页脚。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 044 · Critical edition: line numbers and line-keyed notes ═══
// https://postext.dev/en/cookbook/critical-edition-line-numbers
// Code: MIT · Text: Milton, Poems (1645) (PD) · Notes: CC BY 4.0 · Laurel: diffusion models
// Fonts: Linden Hill, Imbue, Libre Franklin (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// Lycidas in the spelling of 1645, with a number beside every fifth line and two pages of
// notes keyed to those numbers, so the verse carries no note markers.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en')
const RECIPE = 'critical-edition-line-numbers';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// Black text on white, and one laurel green for the apparatus.
const palette = {
  ink: '#1b1b1b', // the text
  laurel: '#3c5a3e', // line numbers, note numbers, the kicker
  muted: '#6a706a', // running heads, the colophon
  paper: '#ffffff',
};
// col(id) carries the hex beside the id of its palette entry.
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' } }));
const [TEXT, DISPLAY, LABEL] = ['Linden Hill', 'Imbue', 'Libre Franklin'];
const LEAD = 14.5; // pt: the leading of the verse, and the grid every page keeps

// #region answer: count the lines, and set every fifth number in the margin
// The poem is one :::verse block, written as 1645 prints it: a line of verse a line, a blank
// line between verse paragraphs and two spaces before a short line. lineNumbers counts its
// lines of verse (a line that turned over would still count once) and prints the multiples
// of five beside their lines, on their baselines. position 'side' puts them in the side
// column of the one-and-a-half layout, flush with its edge next to the verse.
const lineNumbers = {
  enabled: true,
  count: 'verse', // the lines of :::verse poems; the notes are prose and not counted
  interval: 5,
  restart: 'document', // one count through the poem
  position: 'side',
  fontFamily: LABEL, fontSize: pt(7.5), color: col('laurel'),
};
// Hook-up: lineNumbers in the config; the Markdown goes to buildDocument as it is written.
// #endregion

// #region page: a poetry trim, and a channel for the numbers at the fore-edge
const PT = 25.4 / 72; // mm in a point
const [TRIM_W, TRIM_H] = [138, 216]; // mm

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

变化

#每隔十行编号

长诗常按十行编号;6 mm的栏不需要改动。

-  interval: 5,
+  interval: 10,

#行号一律排在诗行右侧

把侧栏固定在右边后,每一页的行号都在诗行右侧,在左页上就靠近订口。

-  sideColumnSide: 'outer', // 右页在诗行右侧,左页在诗行左侧
+  sideColumnSide: 'right', // 每一页都在诗行右侧

常见问题

易错点

属性值:不能含{ or };含"的值用单引号

属性值在右花括号处结束,所以不能包含{ or }。含双引号的值要放在单引号里;美元符号没有问题。 标题属性 →

易错点

标题样式会继承其级别的分页设置

headingStyles中的条目没有写出的字段都取自它所属的标题级别,breakBefore也不例外。在:::pagebreak之后以H1设置样式的目录页或版权页会继承parity 'odd',结果落在一张空白页之后。给这类样式设置breakBefore: { enabled: false }。 标题样式 →

  • 诗节间距在页首会被丢弃,所以第14行与第15行之间的诗节分隔正好落在第1页转第2页处,看不出来。如果你的版本必须显示每个诗节分隔,可以改为让每个诗节的第一行缩进,1645年版正是这样做的:在那一行前加两个空格。
  • 行号与你添加的任何侧框或侧栏题注共用侧栏。落在其上的行号照样印出,沙盒会报告lineNumberOverlap;可以移动那个框,或用position: 'outer'把行号改排到外侧页边。
  • 注释里的行号仍是手写的(:chip[8]{style="line"}):注释目前还不能指向某一行并印出它的行号。改动正文后,要把注释里的行号与页边的行号对照检查。

致谢

文本
  • Lycidas, with its headnote, in the text of Poems of Mr. John Milton (1645), pages 57–65, from the proofread Wikisource transcription of the 1927 facsimile; checked against H. C. Beeching’s Oxford text (Project Gutenberg eBook 1745) · John Milton · 公有领域
  • The note on the text, the notes and the colophon · Ignacio Ferro · CC BY 4.0
图片
  • The sprig of bay laurel on the first page, a watercolour · Generated With Diffusion Models · 原创
字体
Linden Hill (SIL OFL 1.1) · Imbue (SIL OFL 1.1) · Libre Franklin (SIL OFL 1.1)
沙盒