跳到主要内容
食谱编号78

排版食谱 · 第6章 · 框与注释

行内夹批与天头眉批的朱批本

竖排的中文评点本页面:抄本的侧批折成行内两行朱字,眉批排在正文上方的天头一栏。

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

页码四–五 · 第4–5页,共6页

  • 英文样例:尚无中文版本
  • 成品尺寸184 × 260 mm
  • 一栏半, 栏间距8.5 mm
  • Noto Serif TC 12/21
  • LXGW WenKai TC
  • Noto Sans TC
  • 6页
  • 难度
  • Postext 1.65.0
  • 排版用时101 ms
  • 156行代码

简单来说

一部中国古典小说的六页竖排页面。原抄本上的红色批语,有的排进正文行内,有的放在正文上方的一栏里。

成品一览

甲戌本《石头记》是带有脂砚斋评语的抄本,这里把它第一回的开头重排成评点本的六页:16开,184 × 260 mm,竖排右翻。曹雪芹的正文用Noto Serif TC,每列36字,每页18列。抄本把节选中的61条侧批用红笔写在各列旁边。Postext不在两列之间排任何内容,所以本版把每条侧批移入行内,紧跟在它所评的文字之后,以半号字折成两行朱字,就像刻本评点排双行夹批那样。十条眉批用红色楷体排在正文上方42 mm高的天头一栏里,位于所评段落上方,读者读正文和评语一气呵成。

这道食谱解答

  • 怎样排评注本:行内的双行小注和天头的批语?
  • 怎样把中文书排成竖排、右侧装订?

简短回答

script.js · 第38–65行在完整代码中
const layout = {
  writingMode: 'vertical-rl', // columns down the page, read from the right; bound on the right
  layoutType: 'oneAndHalf', // a text tier and a narrow tier for the comments
  sideColumnRole: 'floats', // no text runs into it: only boxes fenced with span="side"
  sideColumnSide: 'left', // in vertical text 'left' is the top tier: the head margin (天頭)
  sideColumnPercent: 19, // the grid rounds it to 10 characters of the body, 42 mm
  gutterWidth: mm(8), // rounded to 2 characters
  columnRule: { enabled: true, lineWidth: pt(0.5), color: col('rule') },
};
const cjk = {
  grid: { enabled: true, charsPerLine: 36, linesPerPage: 18 }, // 版心: 36 字 × 18 行
  // :warichu[…] folds a side comment into two rows at half the body size, in red
  // and with no brackets, as the manuscripts write their 雙行夾批.
  warichu: { color: col('vermilion') },
};
// A 眉批 is :::callout{type="meipi" span="side"}: span="side" sends it to the head
// margin, level with the column the text has reached at its fence, so the fence goes
// just before the passage it discusses (gotcha: side-box-starts-at-fence).
const meipi = {
  id: 'meipi', backgroundEnabled: false,
  border: { enabled: false }, stripe: { enabled: false },
  padding: { top: pt(0), right: pt(0), bottom: pt(0), left: pt(0) },
  // 17 characters of 7 pt down the 120 pt tier, a column every 10 pt. The next comment
  // starts on a text column at least one body column (21 pt) further on, whatever the margin.
  snapToGrid: false, marginBottom: pt(0),
  body: { fontFamily: KAI, fontSize: pt(7), lineHeight: pt(10), color: col('vermilion'),
    textAlign: 'left', firstLineIndent: pt(0) },
};

用料

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

做法

#1 · 把侧栏变成天头

代码就是上面的简短回答。竖排页面是把横排页面旋转90度,所以一栏半版式的侧栏变成横贯页面的一栏,sideColumnSide: 'left'把这一栏放到天头(竖排)。字符网格把sideColumnPercent: 19取整为正文的10个字,即120 pt,栏间距取整为两个字;栏线成为评语与正文之间的细线。评语样式不带框:7 pt楷体,每列17字,这个字号下十条评语没有一条以只有一个字的列结尾;snapToGrid: false让评语按自己10 pt的间距排列,而不是正文的21 pt。

两种评语都标在抄本原有的位置。侧批是:warichu[…]行内片段,由cjk.warichu着色;眉批是一个用span="side"围起的框,紧放在所评段落之前:

:::callout{type="meipi" span="side"}
妙!自謂落墮情根,故無補天之用。
:::
 
原來女媧氏煉石補天之時,:warichu[補天濟世,勿認真,用常言。]于大荒山:warichu[荒唐也。]…

#2 · 把回数和回目排在开头几列

script.js · 第69–81行在完整代码中
const opener = { enabled: true, minHeight: mm(46), slot: { elements: [
  { kind: 'text', id: 'book', content: '{title}', fontFamily: HEI, fontWeight: 500,
    fontSize: pt(10), letterSpacing: pt(3), color: col('vermilion'), align: 'left',
    placement: { anchor: { to: 'container', edge: 'top-left' } } },
  { kind: 'text', id: 'number', content: '{titleText}', fontFamily: SONG, fontWeight: 700,
    fontSize: pt(30), letterSpacing: pt(6), color: col('ink'), align: 'left',
    placement: { anchor: { to: '#book', edge: 'below' }, offset: { x: em(2), y: mm(4) } } },
  ...['a', 'b'].map((half, i) => ({ kind: 'text', id: `couplet-${half}`,
    content: `{attr.${half}}`, fontFamily: SONG, fontSize: pt(15), letterSpacing: pt(3),
    color: col('ink'), align: 'left',
    placement: { anchor: { to: i ? '#couplet-a' : '#number', edge: 'below' },
      offset: { x: i ? pt(0) : em(4), y: mm(i ? 1.5 : 4) } } })),
] } };

在竖排页面上,章首按文字流的坐标排版,所以文字向下走,below指向左边,x偏移让元素沿列向下移。先是红色黑体的书名,然后是30 pt的第一回,下移两个自身字高,再是来自标题属性{a="…" b="…"}的回目上下联,又下移一次,于是回数和回目像刻本回目那样逐级向下错开。minHeight: mm(46)在回目和正文之间留出一列空白。

#3 · 书口处的竖排书眉

script.js · 第85–96行在完整代码中
// 'outer' is the margin away from the spine: a recto's left, a verso's right.
const edge = (id, content, edgeOf, y, extra = {}) => ({ kind: 'text', id, content,
  writingMode: 'vertical-rl', fontFamily: HEI, fontWeight: 500, fontSize: pt(9.5),
  letterSpacing: pt(2), color: col('muted'), overflow: 'clip', align: 'left',
  placement: { anchor: { to: 'outer', edge: edgeOf }, offset: { y: em(y) } }, ...extra });
const header = { elements: [
  // Four characters below the head: the book on a verso, the chapter on a recto,
  // never on the opener.
  edge('head-verso', '{title}', 'top', 4, { pages: 'body', parity: 'even' }),
  edge('head-recto', '{chapterTitle}', 'top', 4, { pages: 'body', parity: 'odd' }),
  edge('folio', '{pageNumber}', 'bottom', -5), // 一, 二, 三…: page.pageNumbering below
] };

这些是竖排文字元素中的书口书眉:anchor.to: 'outer'指远离书脊的页边距,在右翻书里是右页的左边、左页的右边;writingMode: 'vertical-rl'让文字竖排。这里的版心包括评语一栏,所以“天头下四格”是从红色评语的顶端量起。trad-chinese-informal把页码印成一到六。

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

script.js · 第246–258行在完整代码中
// Song sets the whole sample and its bold only 第一回, Kai the head-margin comments and
// the edition's note, Hei the running heads, the folios and the colophon
// (gotcha: cjk-fonts-slices).
const blocks = (style) => [...markdown.matchAll(
  new RegExp(`:::(?:callout|paragraphs)\\{[^}]*"${style}"[^}]*\\}\\n([^]*?)\\n:::`, 'g'))]
  .map((m) => m[1]).join('');
const numerals = '一二三四五六七八九十';
await loadFonts(FONTS, markdown);
await loadCjkFonts({ [SONG]: ['400'] }, markdown, { vertical: true });
await loadCjkFonts({ [SONG]: ['700'] }, '第一回'); // the bold weight sets three characters
await loadCjkFonts({ [KAI]: FONTS[KAI] }, blocks('meipi') + blocks('note'), { vertical: true });
await loadCjkFonts({ [HEI]: FONTS[HEI] }, `脂硯齋重評石頭記第一回${numerals}${blocks('colophon')}`,
  { vertical: true });

Fontsource把每种中文字体按字重各拆成约一百个文件。宋体用常规字重排整个样张,只有第一回用粗体;楷体只排眉批和本编说明;黑体只排书眉、页码和版权页,所以每次调用只取它自己的字符所需的文件。vertical: true还会为Canvas加载每种字体的竖排标点。

#5 · 双色

script.js · 第18–31行在完整代码中
const palette = {
  ink: '#231d18', // the text: a warm black
  vermilion: '#b0362a', // 朱: every comment, the chapter's kicker; 5.5 : 1 on the paper
  rule: '#b9a78f', // the line under the head margin
  muted: '#6f6356', // folios, the colophon
  paper: '#f7f1e3',
};
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: aimed at the vermilion, nothing prints blue.
  { id: 'main-color', name: 'vermilion (defaults)',
    value: { hex: palette.vermilion, model: 'hex' } },
];

页面用两种颜色印刷,和抄本的书写一致:正文用暖黑,每条评语和本章的眉题用朱红,别的都不用。朱红在纸色上的对比度为5.5 : 1,足够排6 pt的侧批双行。main-color指向朱红,所以配置里没有重设的默认值都印成红色,而不会是蓝色。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 078 · Red-ink commentary in the line and the head margin ═══
// https://postext.dev/en/cookbook/red-ink-commentary
// Code: MIT · Text: 脂硯齋重評石頭記, Jiaxu manuscript, Wikisource (CC BY-SA 4.0) · Pictures: none
// Fonts: Noto Serif TC, LXGW WenKai TC, Noto Sans TC (SIL OFL 1.1) · Needs postext ≥ 1.28.0
// The first chapter of the Stone as a commentary edition: the text set vertically, the
// comments the manuscript writes beside the columns folded into two small red rows inside
// the line, the head-margin comments in red Kai above the columns they gloss.
import {
  buildDocument, withLoadedFonts, renderPageToCanvas, loadVerticalAlternates,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'red-ink-commentary';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: black ink and vermilion on a warm paper
const palette = {
  ink: '#231d18', // the text: a warm black
  vermilion: '#b0362a', // 朱: every comment, the chapter's kicker; 5.5 : 1 on the paper
  rule: '#b9a78f', // the line under the head margin
  muted: '#6f6356', // folios, the colophon
  paper: '#f7f1e3',
};
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: aimed at the vermilion, nothing prints blue.
  { id: 'main-color', name: 'vermilion (defaults)',
    value: { hex: palette.vermilion, model: 'hex' } },
];
// #endregion
const [SONG, KAI, HEI] = ['Noto Serif TC', 'LXGW WenKai TC', 'Noto Sans TC']; // 宋, 楷, 黑
const BODY = 12; // pt, 小四: the notes fold to two rows of 6 pt in the same em
const LEAD = 21; // pt between columns, 1.75 × the body

// #region answer: side comments inside the line, head-margin comments above it
const layout = {
  writingMode: 'vertical-rl', // columns down the page, read from the right; bound on the right
  layoutType: 'oneAndHalf', // a text tier and a narrow tier for the comments
  sideColumnRole: 'floats', // no text runs into it: only boxes fenced with span="side"
  sideColumnSide: 'left', // in vertical text 'left' is the top tier: the head margin (天頭)
  sideColumnPercent: 19, // the grid rounds it to 10 characters of the body, 42 mm
  gutterWidth: mm(8), // rounded to 2 characters
  columnRule: { enabled: true, lineWidth: pt(0.5), color: col('rule') },
};
const cjk = {
  grid: { enabled: true, charsPerLine: 36, linesPerPage: 18 }, // 版心: 36 字 × 18 行

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

变化

#评语用单色印刷

单色印刷时,把夹批排成黑色并加括号,眉批用浅墨色;括号以正文字号排在夹批第一行之前和最后一行之后。

-  warichu: { color: col('vermilion') },
+  warichu: { color: col('ink'), open: '〔', close: '〕' },
-  body: { fontFamily: KAI, fontSize: pt(7), lineHeight: pt(10), color: col('vermilion'),
+  body: { fontFamily: KAI, fontSize: pt(7), lineHeight: pt(10), color: col('muted'),

#对比拉丁文字的版本

同样的技法用在横排页面上,就是带页边注释的古典注释本:侧栏位于书口一侧(sideColumnSide: 'outer'),每条注释在所释段落旁边,而不是上方。

常见问题

易错点

侧栏框与其围栏之后的块齐平开始

在postext 1.4.1中,span: 'side'的框在侧栏中的位置,是正文排到其围栏处时的高度,落在下一个网格行上,并排在已在那里的框之下。把旁注围在它所解释的段落之前:围在段落之后,旁注就会从下一段旁边开始。会超出栏底的框会向上滑,在上方框允许的范围内,直到底边落在栏底;仍然放不下的,就等到下一页的侧栏。 旁注 →

易错点

竖排时侧栏变成一层,'left'是最上面一层

当layout.writingMode为'vertical-rl'时,页面相当于把横排页面转了四分之一圈,所以oneAndHalf版式的侧栏变成横贯页面的一层:sideColumnSide 'left'把它放在页头,即眉批的位置,'right'则放在页脚。'outer'和'inner'分别按'right'和'left'处理(一层没有外侧边),所以教科书边栏的'outer'会把注释送到页脚。sideColumnPercent是页面高度的比例。 放浮动体的边栏 →

易错点

中文字体通过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]。 右翻书 →

易错点

用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)。 中文断行 →

  • 眉批与正文排到其围栏时所在的列对齐,所以围栏要紧放在所评段落之前;放在段落之后,评语就从下一段旁边开始。围栏只能位于两个块之间,不能放在段落内部,所以抄本评的是长段中间某句话时,本版就在那里把段落拆开:在石頭聽了之前、在廟傍住着之前,以及石头的答话中竟不如我之前一次;新段落再以「开头,就像跨两段的引语那样。
  • 天头一栏只容纳本页所能容纳的内容。一条评语排不进剩余空间时,会往右退,直到它的最后一列与正文左缘对齐;仍排不下就等下一页,它之后围起的所有评语也一起等。每条评语从一个正文列开始,与前一条之间空出一个正文列。抄本对石头答话的三条评语在天头占十一列:若按抄本的位置围在今之人之前,最后一条斯亦太過会等到第5页,把那里的评语都往后推一步。本版把答话提前一句拆开,放在竟不如我之前,三条就都排在第4页。
  • 网格不用任何设置就让每页排满18列:在字符网格上avoidWidows默认关闭,段落可以从页面的最后一列开始。如果开启,这样的段落会整段移到下一页,这一页少排一列,围在该段之前的评语留在原页。avoidOrphans保持开启,中文网格默认如此:段落的最后一列单独排在一页开头(孤行),是中文编辑要避免的。
  • 前后相连的两条侧批会折成看起来像一条的双行。Markdown在它们之间保留一个全角空格(U+3000)。
  • Noto Serif TC缺少部分抄本字形,如縂、竒和数。Canvas用系统字体补上,PDF则留空并在C25下列出。本版改用这些字的通行字形,保留字体中有的异体。

致谢

文本
  • 脂硯齋重評石頭記 (The Story of the Stone, re-annotated by Zhiyan Zhai), Jiaxu manuscript (1754), chapter 1 from its opening to the Zhen household, with the commentary; Wikisource transcription, revision 2644544 · Cao Xueqin and Zhiyan Zhai; transcription by Wikisource editors · CC BY-SA 4.0
  • The note on this edition (本編說明) and the paragraph breaks added for the head-margin comments · Ignacio Ferro · CC BY 4.0
字体
Noto Serif TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1)
沙盒PDF