跳到主要内容
食谱编号13

排版食谱 · 第1章 · 页面与网格

排在基线网格上的书页

左右对称的双栏页面,版心高度恰好是44个行距,因此正文在栏间和书脊两侧都落在同一套网格上。

本页内容
输出
Canvas
难度
中级
Postext
已用Postext 1.65.0测试
需要≥ 1.46.2
许可证
更新于2026年10月10日
代码MIT · 文本CC BY 4.0

页码9 · 第1页,共3页

  • 英文样例:尚无中文版本
  • 成品尺寸210 × 280 mm
  • 2栏, 栏间距6 mm
  • Vollkorn 9.8/13.4
  • Playfair Display
  • Vollkorn SC
  • 3页
  • 难度
  • Postext 1.57.1
  • 排版用时82 ms
  • 217行代码

简单来说

一篇讲古书版面比例的文章,共三页。示例演示怎样让两栏、左右两页的每一行文字都排在同样的高度上。

成品一览

书籍制作文集The Ruled Page的第9页到第11页,收的是“The Secret Canon”,一篇讨论中世纪抄写员所定页面比例的随笔。它的页边距遵循文中描述的比例法则,即左右对称的2:3:4:6,成品尺寸210 × 280 mm,版心是两栏Vollkorn。页面上用浅红色画出基线网格,两栏以及左右两页的正文都落在网格上。Playfair Display标题占满章首页的第一栏,第二栏栏首是比例法则的示意图。小标题偏离网格半行,其下的正文重新回到网格上。一段字号较小的工作室注释使用自己的10 pt行距。在第11页,随笔在一幅通栏图下以两栏等长结束,版权说明收尾于第二栏。

这道食谱解答

  • 怎样设置书页:成品尺寸、内外对称的页边距、两栏和栏间距?
  • 怎样把文字锁定在基线网格上,让各栏和对页的行对齐?
  • 怎样让各栏底部齐平,最后一页也排得平衡(垂直两端对齐)?
  • 怎样避免段末孤行、段首孤行和只有一个词的末行(孤字),并让标题与正文不分开?

简短回答

script.js · 第32–53行在完整代码中
const LEAD = 13.4; // pt: the body leading is the pitch of the baseline grid
const UNIT = 8; // mm: the margins step 2:3:4:6 in units of 8 mm, like the canon's
const LINES = 44; // lines per column: the text block is a whole number of leads tall
const TRIM = { width: 210, height: 280 }; // mm
const MM_PER_PT = 25.4 / 72;
const page = {
  sizePreset: 'custom', width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150,
  backgroundColor: col('paper'),
  margins: { mirror: true, // left is the inner margin; mirror swaps it on every verso
    left: mm(2 * UNIT), top: mm(3 * UNIT), right: mm(4 * UNIT), // 16, 24 and 32 mm
    bottom: mm(TRIM.height - 3 * UNIT - LINES * LEAD * MM_PER_PT) }, // 48 mm: six units
  // The layout keeps to the grid whether or not the overlay draws it.
  baselineGrid: { enabled: true, color: col('grid') },
};
const GUTTER = 6; // mm: 162 mm of text block make two columns of 78 mm
const layout = { layoutType: 'double', gutterWidth: mm(GUTTER),
  columnRule: { enabled: true, color: col('rule'), lineWidth: pt(0.4) } };
const body = { fontFamily: 'Vollkorn', fontSize: pt(9.8), lineHeight: pt(LEAD) };
// Lists add no space of their own (any whole number of leads would do). The grid never
// absorbs a list's top margin: the default 1.5 em (14.7 pt here) would set the items
// 1.3 pt off the lines of the column beside them, until the list reaches a new column.
const onGrid = { marginTop: pt(0), marginBottom: pt(0) };

用料

类型
Vollkorn, Playfair Display, Vollkorn SC(SIL OFL 1.1)
素材
  • The two drawings, made in code in the page's palette (Postext Cookbook, CC BY 4.0)

做法

#1 · 让标题离开网格,但列表不行

script.js · 第99–112行在完整代码中
  headings: { fontFamily: 'Playfair Display', color: col('ink'), balancing,
    levels: [
      // parity 'odd': the essay opens on a recto.
      // Two lines of 46 pt, each four leads tall, then one lead: the text starts on line 10.
      { level: 1, breakBefore: { enabled: true, parity: 'odd' },
        fontSize: pt(46), lineHeight: pt(4 * LEAD), italic: true, color: col('rubric'),
        marginBottom: pt(LEAD) },
      // A lead and a half above puts the head between two grid lines. The margin below
      // needs no fitting: the engine snaps the text under a head to the next grid line.
      { level: 2, fontSize: pt(12.5), lineHeight: pt(LEAD), marginTop: pt(1.5 * LEAD) },
    ] },
  // Lists add no space of their own (onGrid, in the short answer): items stay on the grid.
  unorderedLists: { ...onGrid, bulletChar: '–', color: col('rubric'), fontWeight: 400 },
  orderedLists: { ...onGrid, color: col('rubric') }, // numbers in the rubric, text in ink

标题上方的间距严格按设定保留,所以1.5个行距会让标题落在两条网格线之间,标题下的正文则对齐到下一条网格线(基线网格)。列表在第一项之前不会对齐网格,所以简短回答把列表的外边距设为零(任何整数倍行距也可以);如果用默认的1.5 em,第10页的三个列表项会比旁边一栏的行线低1.3 pt。标题的两行46 pt各占四个行距,下外边距再占一个,所以随笔从第10行开始。

第10页:第二栏里的列表与旁边段落的网格保持一致;工作室注释落在网格线之间,下面的标题偏离网格半行,标题下的正文又回到网格上。

#2 · 有意离开网格,再回来

script.js · 第115–120行在完整代码中
  paragraphStyles: [
    { id: 'note', fontSize: pt(7.8), lineHeight: pt(10), color: col('muted'),
      boldColor: col('rubric'), firstLineIndent: pt(0), marginTop: pt(LEAD / 2) },
    { id: 'colophon', fontFamily: 'Vollkorn SC', fontSize: pt(7.5), lineHeight: pt(10),
      color: col('muted'), textAlign: 'left', firstLineIndent: pt(0), marginTop: pt(LEAD) },
  ],

注释是一个:::paragraphs容器,字号7.8 pt、行距10 pt,不在网格上。最后一段结束后,位置向上取整到下一条网格线,所以后面的标题与跟在正文后时的位置相同(:::paragraphs容器)。版权说明用同样的容器,字号7.5 pt、行距10 pt:四行占40 pt,比三个行距少0.2 pt,因此随笔的最后一栏与旁边一栏齐底。

#3 · 把图放在网格能消化的地方

script.js · 第319–332行在完整代码中
// mm: a column wide and just short enough for a 17-lead band with its caption; a block wide
const CANON = [COLUMN_W, 61.8], PAGES = [BLOCK_W, 64];
const figure = (id, [width, height], placement, [caption, altText]) => ({
  id, typeId: 'figure', kind: 'svg', svg: { fileId: `${id}.svg`, width, height },
  placement, caption, altText, createdAt: 0, updatedAt: 0,
});
const resources = [
  // A float never lands above the paragraph that cites it. A column 'top' float cited in
  // the first column can still take the head of the second, on the same page.
  figure('canon', CANON, { position: 'top' }, t(CAPTIONS.canon)),
  // A page-wide 'top' float cannot, so it waits for the next page (gotcha: top-float-next-page).
  // Each band is rounded up to whole leads, so the text under it stays on the grid.
  figure('pages', PAGES, { position: 'top', span: 'page' }, t(CAPTIONS.pages)),
];

浮动体永远不会落在引用它的段落之上(位置)。比例法则示意图在第一栏被引用,仍然可以占据第9页第二栏的栏首;占满页宽的对比图在第10页被引用,要等到第11页。每个图带的高度都向上取整为整数个行距,所以图下的正文从网格线开始,与旁边一栏和对页齐平。图的尺寸要考虑这种取整:比例法则示意图宽61.8 mm时,连同题注占17个行距;宽62.5 mm就要占18个,题注下会留出将近一行的空白。

第11页:通栏图下的正文从网格线开始,随笔以两栏齐底结束,版权说明收尾于第二栏。

#4 · 让各栏齐底来补齐栏位

script.js · 第86–87行在完整代码中
// On by default: it fills a column a keep rule leaves short, and cuts the last page level.
const balancing = { enabled: true };

第9页和第10页每个排满的栏都结束在第44行,因为版心恰好是44个行距,文稿也按它调整过。与下段同页,以及段末孤行、段首孤行和孤字规则默认都是开启的。如果其中某条规则让一栏少了一行,各栏齐底会把缺少的空间加到前面某个标题的上方(各栏齐底),在那里显出一道空隙,所以要调整文稿,直到各栏齐底无需填补为止。在最后一页,它把剩下的行分配好,让两栏结束在同一行。

#5 · 页边距左右对称,页码从9开始

script.js · 第57–82行在完整代码中
const OUTER = 4 * UNIT; // mm: the heads end where the text block does
const RISE = 1.5 * UNIT; // mm: heads 12 mm into the head margin; the drop folio 12 mm below
const TAB = 7; // mm from a folio to the title beside it
const onPage = (edge, x) => ({ anchor: { to: 'page', edge },
  offset: { x: mm(x), y: mm(RISE) } });
const head = (id, content, parity, placement, extra = {}) => ({
  kind: 'text', id, content, parity, placement, pages: 'body', // never on the opener
  fontFamily: 'Vollkorn SC', fontSize: pt(8.5), fontWeight: 600, letterSpacing: pt(0.8),
  color: col('muted'), ...extra,
});
const folio = { fontFamily: 'Vollkorn', fontWeight: 700, letterSpacing: pt(0),
  color: col('rubric') };
const header = { elements: [
  head('verso-folio', '{pageNumber}', 'even', onPage('top-left', OUTER), folio),
  head('verso-title', '{title}', 'even', onPage('top-left', OUTER + TAB)),
  head('recto-title', '{chapterTitle}', 'odd', onPage('top-right', -(OUTER + TAB))),
  head('recto-folio', '{pageNumber}', 'odd', onPage('top-right', -OUTER), folio),
] };
// The opener drops its folio into the foot margin, centred under the text block.
const underBlock = { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(RISE) } };
const footer = { elements: [
  head('drop-folio', '{pageNumber}', 'all', underBlock, { ...folio, pages: 'opener' }),
] };
// startAt prints the folios from 9; pageIndexOffset counts the 8 pages before them, so
// mirroring, parity and breakBefore follow the book (7 would add a blank page).
const continuation = { pageIndexOffset: 8, pageNumbering: { startAt: 9 } };

简短回答算出了下页边距:280 mm的成品高度减去24 mm的上页边距,再减去恰好LINES个行距的版心(44 × 13.4 pt = 208 mm),剩下48 mm,即六个单位,符合2:3:4:6的比例。设了mirror: true后,作为left设定的16 mm就是内页边距,在右页位于左侧,在左页位于右侧(对称页边距),所以锚定在距页面边缘OUTER毫米处的书眉会在切口一侧与版心同时结束;pages: 'body'让章首页不印书眉。startAt: 9印出第9到第11页的页码,pageIndexOffset: 8计入之前的八页,于是左右对称、书眉的奇偶和breakBefore: 'odd'都与装订成书时一致。如果偏移量设为7,第一页会算作左页,奇数页分页会在随笔前插入一张空白页。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 013 · A book page on a baseline grid ═════════════════════
// https://postext.dev/en/cookbook/baseline-grid-book-page
// Code: MIT · Text: original (CC BY 4.0) · Pictures: drawn in code (CC BY 4.0)
// Fonts: Vollkorn, Playfair Display, Vollkorn SC (SIL OFL 1.1) · Needs postext ≥ 1.46.2
// An essay on the canon of page proportions, on a page that shows its geometry and grid.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the sample document's language ('en' | 'es' | 'pt' | 'fr' | 'de' | 'it')
const RECIPE = 'baseline-grid-book-page';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// A scribe's colours: ink, one rubric red and the pale red of a ruled page.
const palette = {
  ink: '#211d1a', // text: a warm near-black
  rubric: '#b3261e', // the one accent: title, numbers, folios, the drawings' lines
  grid: '#efc6bd', // the baseline grid, as pale as a manuscript's ruling
  rule: '#d5cbbb', // the column rule and the drawings' hairlines
  muted: '#716860', // running heads, the workshop note, the colophon (5.1:1 on paper)
  tint: '#ede4d3', // the ground of the drawings
  paper: '#fbf8f1',
};
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' } })),
  // Defaults this config does not restate link to main-color: point it at the rubric.
  { id: 'main-color', name: 'rubric (defaults)', value: { hex: palette.rubric, model: 'hex' } },
];

// #region answer: one grid for the whole spread: trim, mirrored margins, two columns, leading
const LEAD = 13.4; // pt: the body leading is the pitch of the baseline grid
const UNIT = 8; // mm: the margins step 2:3:4:6 in units of 8 mm, like the canon's
const LINES = 44; // lines per column: the text block is a whole number of leads tall
const TRIM = { width: 210, height: 280 }; // mm
const MM_PER_PT = 25.4 / 72;
const page = {
  sizePreset: 'custom', width: mm(TRIM.width), height: mm(TRIM.height), dpi: 150,
  backgroundColor: col('paper'),
  margins: { mirror: true, // left is the inner margin; mirror swaps it on every verso
    left: mm(2 * UNIT), top: mm(3 * UNIT), right: mm(4 * UNIT), // 16, 24 and 32 mm
    bottom: mm(TRIM.height - 3 * UNIT - LINES * LEAD * MM_PER_PT) }, // 48 mm: six units
  // The layout keeps to the grid whether or not the overlay draws it.
  baselineGrid: { enabled: true, color: col('grid') },
};
const GUTTER = 6; // mm: 162 mm of text block make two columns of 78 mm
const layout = { layoutType: 'double', gutterWidth: mm(GUTTER),
  columnRule: { enabled: true, color: col('rule'), lineWidth: pt(0.4) } };

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

变化

#交付印刷时隐藏网格

enabled只控制成品页面上画出的网格线;无论如何版面都遵循13.4 pt的网格,所以没有任何一行会移动。

-  baselineGrid: { enabled: true, color: col('grid') },
+  baselineGrid: { enabled: false },

#看看各栏齐底做了什么

关闭各栏齐底后,第11页会把最后八行和版权说明都排进第一栏,第二栏留空。

-const balancing = { enabled: true };
+const balancing = { enabled: false };

常见问题

易错点

'top'浮动体默认排在引用页的下一页,除非允许它置于引用页顶

默认情况下浮动体不会排在自己的引用之前,所以在第N页引用的整页宽'top'浮动体会出现在第N+1页的顶部。在资源或其类型的defaultPlacement上设置placement.citingPage: true(或者对全书设置layout.floatsAtCitingPage,自postext 1.25起),它就改为置于第N页顶部,引用处之上的文字移到它下方,前提是它不超过layout.maxTopFraction且引用行仍留在该页。它不会置于章首页或强制分页之后的页面顶部:那时仍排在下一页,而'auto'或'bottom'可以占用引用页的底部。 图的放置 →

  • top浮动体永远不会落在引用页的规则,适用于占满页宽的浮动体。栏内的top浮动体可以落在引用页上,位于后面一栏的栏首,就像第9页的图1.1那样。
  • 页面尺寸、页边距和栏间距使用绝对单位(mm、pt、cm、in)。在这些地方用em没有可参照的字号,构建会停止并报错“dimensionToPx: baseFontSizePx is required for unit "em"”。
  • Vollkorn的词间距很窄,只有0.2 em,所以在大约50个字符宽的栏里,有些两端对齐的行会显得松散或拥挤。示例文字是对照截图的松行报告逐行调整过的;正文或行长有任何改动后都要重新检查。

致谢

文本
  • The essay “The Secret Canon” and its Spanish version “El canon secreto”, written for this recipe · Postext Cookbook · CC BY 4.0
图片
  • The two drawings, made in code in the page's palette · Postext Cookbook · CC BY 4.0
字体
Vollkorn (SIL OFL 1.1) · Playfair Display (SIL OFL 1.1) · Vollkorn SC (SIL OFL 1.1)
沙盒