跳到主要内容
食谱编号85

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

刻本书叶:四周双边、界行与版心

照刻本的样子排朱熹《论语集注》:一叶占一个跨页,四周双边,行间有界行,折缝处是版心。

本页内容
类型
教科书
输出
Canvas · PDF
难度
中级
Postext
已用Postext 1.65.0测试
需要≥ 1.25.0 · postext-pdf ≥ 1.25.0
许可证
更新于2026年10月10日
代码MIT · 文本CC BY 4.0

第2–3页,共7页

  • 英文样例:尚无中文版本
  • 成品尺寸120.8 × 213.1 mm
  • 1栏
  • Noto Serif TC 20/29
  • LXGW WenKai TC
  • 7页
  • 难度
  • Postext 1.65.0
  • 排版用时65 ms
  • 178行代码

简单来说

一部儒家经典,按古代木刻本的样子排版。每页有双线边框,列与列之间有细线,注释用小字排在正文行内。

成品一览

在一张内封之后,照刻本的样子排出朱熹《论语集注》(論語集註)开头《学而》篇的三叶。每页是半叶,121 × 213 mm,每个跨页是完整的一叶,从右往左读:每半叶九行,每行17字,用20 pt的Noto Serif TC,四周双边,每两行之间一条细线;折缝处是版心,上有书名、黑鱼尾、卷次和叶码。朱熹的注文用10 pt的小字折成双行,排在所注文字之后的行内。天头是地脚的两倍。

这道食谱解答

  • 怎样排雕版书叶:双线边框、行间界线和中间的版心?
  • 怎样按字数设定版心,每行多少字、每页多少行?
  • 怎样把中文书排成竖排、右侧装订?

简短回答

script.js · 第46–64行在完整代码中
// A block printed both halves of a leaf (葉) at once, the centre strip between them. Each
// page here is a half-leaf. Page 1, the title, is a recto: in a book bound on the right it
// stands alone left of the spine, and every spread after it is one leaf, read from the
// right. The grid sets the block's 9 columns of 17 characters; the text has no
// punctuation, so every column ends on its 17th character.
const page = {
  sizePreset: 'custom', width: pt(W), height: pt(H), dpi: 150,
  backgroundColor: col('paper'),
  // left is the inner margin, the half of the centre strip on this side of the fold
  margins: { top: pt(TOP), bottom: pt(BOTTOM), left: pt(HALF), right: pt(OUTER), mirror: true },
};
const layout = { layoutType: 'single', writingMode: 'vertical-rl' }; // bound on the right
const cjk = { grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES } };
// Postext numbers pages, not leaves. Each leaf opens with a hidden level-1 heading, which
// prints nothing and starts a right-hand page; the centre strip prints their count.
const leaf = {
  level: 1, hidden: true, numberingTemplate: '{1:一}', // 一, 二, 三
  breakBefore: { enabled: true, parity: 'even' }, // even pages lie on the right in this binding
};

用料

类型
Noto Serif TC, LXGW WenKai TC(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 一页半叶,一个跨页一叶

代码见上文的简短回答。一块书版一次印出一整叶(葉),两个半叶分在版心两侧;印工沿版心把纸对折,印面朝外,再把开口的一边缝起来,于是版心成了书的书口。这里的页面保持书叶刚从书版上印下来时的样子,每页是半叶。在右侧装订的书中,第1页单独位于书脊左侧,此后每个跨页都由右边的偶数页和它后面的奇数页组成,所以内封放在第1页,每个跨页就正好是一叶。字格网格设定书版的行款,九行,每行17字,它留下的页边距是精确的:内侧页边距正好是版心的一半。

Postext给页面编号,不给书叶编号。每叶都以一个隐藏的一级标题开头:它什么都不印,也不占位置,但它带parity: 'even'的breakBefore会从一个右页开始,它的编号(由numberingTemplate: '{1:一}'得到一、二、三)就是版心所用的{chapterNumber}。

#2 · 在每叶结束处断开正文

为刻工写样的抄手按书版一叶一叶地安排文字,Markdown也这样做:一叶的标题放在上一叶左半叶第九行结束的地方,即使那里在一句话或一段注文中间。在那里被截断的注文先关闭,再重新打开;由于每行都把自己那部分注文折成两行,双行小注排出来和原来一样:

子曰巧言令色鮮矣仁:warichu[巧好令善也好其言善其色致飾於]
 
# 學而
 
:warichu[外務以悦人則人欲肆而本心之德亡矣…]

书版没有标点,所以没有哪条避头尾规则会挪动字,每行都在第17字结束:叶的断点只需数一次,之后不会变。朱熹的注文是:warichu[…],使用默认的一半字号,每行34个小字,读音和释义之间像刻本一样用○隔开。

#3 · 用网格的数值画出书版

script.js · 第68–113行在完整代码中
// Header elements are placed on the sheet, pt from the page's top left corner. Both halves
// read right to left: a right-hand page (even) from the outer frame to the fold, a
// left-hand page (odd) from the fold to the outer frame.
const at = (x, y) => ({ anchor: { to: 'page', edge: 'top-left' }, offset: { x: pt(x), y: pt(y) } });
// A column of characters stands in the middle of its pitch, so the rules between columns
// fall on whole pitches. The k-th, counted from the right edge of the type area:
const line = (parity, k) =>
  (parity === 'even' ? HALF + LINES * PITCH : W - HALF) - k * PITCH;
const [Y0, Y1] = [TOP - GAP, TOP + CHARS * BODY + GAP]; // the inner frame's top and foot
// A rule is drawn from its x, a box's border inside the box: each is set so that the line
// is centred where it belongs.
const rule = (id, x, parity) => ({ kind: 'rule', id, parity, direction: 'vertical',
  thickness: pt(0.6), color: col('rule'),
  placement: { ...at(x - 0.3, Y0), size: { height: pt(Y1 - Y0) } } });
const frame = (id, [x0, x1], parity) => [[RULES, 1.8], [0, 0.6]].map(([out, t], i) => ({
  kind: 'box', id: `${id}-${i}`, parity, style: { borderColor: col('rule'), borderWidth: pt(t) },
  placement: { ...at(x0 - out - t / 2, Y0 - out - t / 2),
    size: { width: pt(x1 - x0 + 2 * out + t), height: pt(Y1 - Y0 + 2 * out + t) } } }));
// The middle of the strip, where its text stands: the fold, halfway between its two rules.
// Both pages draw the text whole, and each shows its half.
const mid = (parity) => (parity === 'even' ? 0 : W);
const strip = (id, content, parity, y) => ({ kind: 'text', id: `${id}-${parity}`, parity,
  content, writingMode: 'vertical-rl', fontFamily: SONG, fontSize: pt(11), color: col('ink'),
  align: 'left', overflow: 'clip',
  placement: { ...at(mid(parity) - HALF, TOP + y),
    size: { width: pt(2 * HALF), height: pt(CHARS * BODY - y) } } });
// The fish tail (魚尾): a black band with a notch, from one side of the strip to the other.
const FISH = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 18">
  <path d="M0 0H32V13L16 6L0 13Z" fill="${palette.rule}"/></svg>`;
const resources = [{ id: 'fish', typeId: 'figure', kind: 'svg', createdAt: 0, updatedAt: 0,
  svg: { fileId: 'fish.svg', width: 32, height: 18 } }];
const fish = (parity) => ({ kind: 'image', id: `fish-${parity}`, parity, resourceId: 'fish',
  decorative: true, placement: { ...at(mid(parity) - HALF + 0.3, TOP + 3.4 * BODY),
    size: { width: pt(2 * HALF - 0.6), height: 'auto' } } });
const furniture = (parity) => [
  // The frame runs 40 pt past the fold, where the other half of the leaf takes it on.
  ...frame(`frame-${parity}`, parity === 'even' ? [-40, line(parity, 0)]
    : [line(parity, LINES), W + 40], parity),
  // Nine rules: eight between the columns (界行) and the side of the strip.
  ...Array.from({ length: LINES }, (_, i) =>
    rule(`rule-${i}-${parity}`, line(parity, parity === 'even' ? i + 1 : i), parity)),
  strip('book', '{title}', parity, 0.7 * BODY), // 書名, above the fish tail
  fish(parity),
  strip('juan', '卷一', parity, 5.2 * BODY), // 卷次, under it
  strip('leaf', '{chapterNumber}', parity, 11.5 * BODY), // 葉碼, the leaf's number
];

页眉排在整张纸上,所以框、界行和版心都用设定网格的那些数值,从页面一角以点为单位定位:在文字区域内每隔29 pt放一个线条元素,在正文外4.5 pt处放一个方框作细线,再往外4.5 pt放另一个作粗线。每行字都居于自己行宽的正中,所以界行正好落在相邻两行的中间。版心的文字由竖排文本元素自上而下排出,鱼尾是一个SVG图片元素,两者都居中于版心的两条线之间,也就是折缝上:每页显示版心的17 pt。每页都把版心文字和鱼尾完整地画出来,只显示自己这一侧的部分,两页并排时两部分就对上了。框线越过折缝也是同样的道理。

#4 · 给内封一个自己的样式

script.js · 第117–143行在完整代码中
// A heading style of its own: hidden and unnumbered, so the leaves still count from 一, and
// its header replaces the leaves' furniture on its page. Its attributes hold the byline,
// this edition's note in red and the colophon, the one line that changes with the language.
const CELLS = [0, 2, LINES - 2, LINES]; // the byline, title and note, in pitches from the right
const cell = (i) => [CELLS[i], CELLS[i + 1]];
const column = (id, content, [k0, k1], style) => ({ kind: 'text', id, content,
  writingMode: 'vertical-rl', color: col('ink'), overflow: 'clip', verticalAlign: 'middle',
  placement: { ...at(line('odd', k1), TOP),
    size: { width: pt((k1 - k0) * PITCH), height: pt(CHARS * BODY) } }, ...style });
const titlePage = {
  id: 'title', numbered: false, hidden: true, breakBefore: { enabled: true, parity: 'any' },
  footer: { elements: [] },
  header: { elements: [
    ...frame('title-frame', [line('odd', LINES), line('odd', 0)]),
    rule('title-rule-1', line('odd', CELLS[1])), rule('title-rule-2', line('odd', CELLS[2])),
    column('byline', '{attr.byline}', cell(0), { fontFamily: SONG, fontSize: pt(14),
      align: 'left' }),
    column('book', '{title}', cell(1), { fontFamily: KAI, fontSize: pt(60),
      letterSpacing: pt(20), align: 'center' }),
    column('note', '{attr.note}', cell(2), { fontFamily: KAI, fontSize: pt(11),
      lineHeight: pt(0.6 * PITCH), color: col('vermilion'), align: 'right' }), // 3 in 2 pitches
    { kind: 'text', id: 'colophon', content: '{attr.colophon}', fontFamily: SONG,
      fontSize: pt(6.5), lineHeight: 1.4, color: col('muted'), align: 'left', overflow: 'wrap',
      placement: { ...at(line('odd', LINES) - RULES - 0.9, Y1 + RULES + 16),
        size: { width: pt(LINES * PITCH) } } },
  ] },
};

内封(內封)是一个一级标题,使用一个隐藏且不编号的标题样式,所以书叶仍从一开始计数。样式管辖其所在章节的页面,它的header在那里取代文档的页眉:内封得到一个封闭的、分成三栏的框,而不是半叶的那些版面元素。署名、本版的红色楷体说明和版权说明来自标题的属性;版权说明是唯一一行随版本语言而变的文字。属性中的\n另起一栏。

#5 · 每种字体只加载它要排的字

script.js · 第200–205行在完整代码中
// Song sets the leaves, the strip and its leaf numbers; Kai only the title page's title
// and note (gotcha: cjk-fonts-slices). No punctuation: no vertical forms to load.
const note = markdown.match(/note="([^"]*)"/)?.[1].replaceAll('\\n', '') ?? '';
await loadFonts(FONTS, markdown); // their Latin files: the colophon
await loadCjkFonts({ [SONG]: FONTS[SONG] }, `${markdown}論語集註卷一二三四五六七八九十`);
await loadCjkFonts({ [KAI]: FONTS[KAI] }, `論語集註${note}`);

Fontsource把每种中文字体的每个字重拆成大约一百个文件。宋体排书叶、版心和叶码,所以它的调用传入样本文本和这些字;楷体只排书名和说明。书版没有标点,所以两种字体都不需要loadCjkFonts(…, { vertical: true })提供的竖排字形。

#6 · 暖色纸上只用一种墨

script.js · 第19–30行在完整代码中
const palette = {
  ink: '#1f1b17', // the text, as the block printed it
  rule: '#1f1b17', // the frame, the column rules and the fish tail: the same block, same ink
  vermilion: '#a3301f', // 朱: this edition's note, on the title page; 5.9 : 1 on the paper
  muted: '#6d6358', // the colophon
  paper: '#f2ead8',
};
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' } })),
  { id: 'main-color', name: 'defaults', value: { hex: palette.ink, model: 'hex' } },
];

正文和书版的线条用同一种暖黑色印刷,与纸色的对比度为14 : 1。它们仍是调色板中的两项,ink和rule,这样可以只改线条的颜色而不动正文。红色留给本版添加的内容。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 085 · A woodblock leaf: double frame, rules and centre strip ═══
// https://postext.dev/en/cookbook/woodblock-leaf
// Code: MIT · Text: 論語集註 卷一, 四庫全書 copy, zh.wikisource (CC BY-SA 4.0) · Pictures: none
// Fonts: Noto Serif TC, LXGW WenKai TC (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// A title page and three leaves of Zhu Xi's commentary on the Analects, set as a woodblock
// printed them: each spread is one leaf, its two halves either side of the centre strip
// (版心), the text in a double frame with a rule between every two columns, the commentary
// folded into two small rows inside the column.
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the colophon; the leaves are Chinese in both
const RECIPE = 'woodblock-leaf';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one ink on a warm paper, and a red for the editor's note
const palette = {
  ink: '#1f1b17', // the text, as the block printed it
  rule: '#1f1b17', // the frame, the column rules and the fish tail: the same block, same ink
  vermilion: '#a3301f', // 朱: this edition's note, on the title page; 5.9 : 1 on the paper
  muted: '#6d6358', // the colophon
  paper: '#f2ead8',
};
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' } })),
  { id: 'main-color', name: 'defaults', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion
const [SONG, KAI] = ['Noto Serif TC', 'LXGW WenKai TC']; // 宋: the block's face; 楷: the title
// The leaf in points: 半葉九行,行十七字, a 20 pt character on a column pitch of 29 pt.
const [BODY, PITCH, CHARS, LINES] = [20, 29, 17, 9];
const HALF = 17; // half the centre strip, from the fold to the column rule beside it
const GAP = 4.5; // the text to the inner frame line, as a character to a column rule
const RULES = 4.5; // the thin inner frame line to the heavy outer one (文武線)
const [HEAD, FOOT, SIDE] = [164, 82, 60]; // paper outside the frame: 天頭 twice 地腳
const TOP = HEAD + RULES + GAP; // the page's margins
const BOTTOM = FOOT + RULES + GAP;
const OUTER = SIDE + RULES;
const W = HALF + LINES * PITCH + OUTER; // a half-leaf, 121 × 213 mm
const H = TOP + CHARS * BODY + BOTTOM;

// #region answer: a half-leaf to a page, so that every spread is one whole leaf
// A block printed both halves of a leaf (葉) at once, the centre strip between them. Each
// page here is a half-leaf. Page 1, the title, is a recto: in a book bound on the right it
// stands alone left of the spine, and every spread after it is one leaf, read from the

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

变化

#用红色画界行

为《四库全书》缮写的本子用的是画好红格的纸(朱丝栏)。改一下线条颜色即可,鱼尾会跟着变。

-  rule: '#1f1b17', // 框、界行和鱼尾:同一块书版,同一种墨
+  rule: '#b3412e', // 朱丝栏:黑字红格

#换一种行款

书版的行款有很多种,半葉十行,行二十字是最常见的一种。框、版心、内封的三栏和署名的缩进都由这些数值算出,所以会跟着变;Markdown中的叶断点则要重新数。

-const [BODY, PITCH, CHARS, LINES] = [20, 29, 17, 9];
+const [BODY, PITCH, CHARS, LINES] = [17, 24.5, 20, 10];

#与欧洲的网格页面对照

排在基线网格上的书页用行数构建文字区域,就像这张书叶用行和字构建自己的文字区域;证书在标题样式的页眉里画边框,和这里的内封做法相同。

常见问题

易错点

用zh-Hans或zh-Hant标记文档,不要用LANG

食谱的版本是en和es,但中文示例在两个版本里都是中文:`locale: LANG`会把它标记为英文或西班牙文,给其中的拉丁文词断词,把图标注为Figure或Figura,并给PDF标上错误的语言。postext 1.30起,这个标记也是文字成形所用的语言(测量、绘制和嵌入都按它进行),所以标记成英文或西班牙文时,中文字体的数字和与拉丁文共用的标点会换成另一套字形,断行的位置也随之改变。自己写出标记:'zh-Hans'(大陆规范:GB断行规则、开明式标点)或'zh-Hant'(台湾:全角居中标点);香港用'zh-HK'。单写'zh'按简体、大陆规范处理。日文示例写'ja'(见gotcha ja-locale-tag)。 中文断行 →

易错点

中文字体通过cjk块分片加载

Fontsource把一个中文、日文或韩文字体家族按每个字重约一百个文件提供,每个文件覆盖一段字符范围。loadFonts只获取latin文件,所以屏幕上的汉字来自系统字体,测量不准;fontsourceProvider交给PDF的也是这个latin文件,汉字印出来是空框。列出kit中的cjk块,在loadFonts之后调用loadCjkFonts(FONTS, markdown)(书中用到几种CJK字体时,每种字体调用一次,并传入它所排的文字),并给renderToPdf传fontProvider: cjkPdfProvider:两者都会取用包含文中字符的那些文件。 中日韩字体 →

易错点

右装订的书用showBook显示跨页

在右装订的书中(阿拉伯文、希伯来文或波斯文,竖排中文,或page.binding 'right'),第1页仍是奇数页(recto),但它位于书脊左侧,跨页读作[3 | 2]。showPages把所有书都按左装订排列;book块中的showBook(cjk块中也有同一个函数)读取doc.binding,把跨页左右镜像。capture.hero仍按阅读顺序[偶数页, 奇数页]指定跨页:[2, 3]。 右翻书 →

易错点

繁体录入本夹杂零星简体字

从维基文库或其他网络版本复制的繁体书文字,有时夹着简体字形(《三國演義》第一回中以颙代顒),而Noto Serif TC这类TC字体可能没有这个字。loadCjkFonts会中止pen,并在消息中给出这个字符;在页面上,它会用后备字体印出。在示例中恢复繁体字形,并在出处说明中注明。 中日韩字体 →

  • 叶断点写在Markdown里。改动正文、字号或行款后,一叶排不下时会把下一个标题推到下一页,跨页就和书叶对不上了;一叶排不满时,折缝前会留下空行。要检查每个左页的最后一行。
  • 《四库全书》的录文把已和己都录成巳;这个样本根据句意逐个判断。页面仍需对照书影校对,这一点看得出来:张敬夫的话录作必開其政,而他所引的《论语》原文是必聞其政,另有两个字是字形的图片。样本排作聞、傳和邦。排一段文字之前,先用另一个版本核对。
  • 同一份录文中有Noto Serif TC没有字形的字(廹 徳 絶 逺 専 内)。其中五个落在某个Fontsource文件的范围内,所以loadCjkFonts会放行,结果Canvas用系统字体画出它们,postext-pdf则印出空框并发出警告。廹不在任何文件的范围内,loadCjkFonts会报错停止。样本排作迫 德 絕 遠 專 內。

致谢

文本
  • 論語集註 (Collected Commentaries on the Analects), juan 1, the book 學而 from its opening to the end of its tenth section, in the copy made for the 四庫全書 (Siku quanshu, 1773–1782); Wikisource transcription, revision 523110. 巳 is read as 已 or 己 by its sentence; 開 in 張敬夫's 必開其政 is corrected to 聞, as in the words of the Analects he repeats and in Wikisource's other edition (論語集注卷一, revision 2598582); the two characters the transcription gives as glyph images are set as 傳 (以忠信為傳習之本) and 邦 (夫子至於是邦也); and six variant forms Noto Serif TC does not draw (廹 徳 絶 逺 専 内) are set in their standard forms · Zhu Xi (1130–1200); transcription by Wikisource editors · CC BY-SA 4.0
  • The title page, the division into leaves and the note on this edition (據四庫全書本錄文…) · Ignacio Ferro · CC BY 4.0
字体
Noto Serif TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1)
沙盒PDF