简单来说
《三国演义》第一回,排成台湾的平装本。正文竖排,从右往左读,书也从右边翻开。
成品一览
一本台湾平装版《三國演義》的十一页:毛宗岗评本的第一回全文,在148 × 210 mm(25開)、右侧装订的页面上从上到下竖排,各行从右向左读。书名页独自位于书脊左侧。下一个跨页上,1592年刻成的桃园结义木刻与本回的开头相对,开头的第一回和回目对联排在朱红线之间。每一页正文16行、每行40字,每个字符居于自己的字格中央。右页的外页边距竖排书名,左页的外页边距竖排回目,下面是中文数字页码。同样的图书结构放在欧洲平装本里,见Nº 038。
这道食谱解答
- 怎样把中文书排成竖排、右侧装订?
- 怎样用中文数字给章编号,排出第一回、第二回?
简短回答
// 'vertical-rl' turns the flow a quarter turn: lines run down, columns from right to left,
// and page.binding 'auto' becomes 'right', so page 1 is a left-hand page and the spreads
// read [3 | 2]. The grid sets the type area in characters; the margins are minimums it
// grows. zh-Hant resolves to Taiwan's rules: every mark full width and centred in its cell.
const page = {
sizePreset: 'custom', width: mm(148), height: mm(210), dpi: 150,
backgroundColor: col('paper'),
// 天頭 above 地腳; left is the spine side (the right edge of a left-hand page).
margins: { top: mm(32), bottom: mm(26), left: mm(16), right: mm(22), mirror: true },
pageNumbering: { format: 'trad-chinese-informal' }, // folios 一, 二 … 九, from the chapter
};
const layout = { layoutType: 'single', writingMode: 'vertical-rl' };
const cjk = { grid: { enabled: true, charsPerLine: 40, linesPerPage: 16 } };
const chapter = {
level: 1, numberingTemplate: '第{1:一}回', numberSeparator: ' ', // 第一回 宴桃園…
breakBefore: { enabled: true, parity: 'odd' }, // a recto, with no blank page forced
marginBottom: pt(0),
};
用料
- 类型
- Noto Serif TC, LXGW WenKai TC, Noto Sans TC, Source Serif 4(SIL OFL 1.1)
- 素材
peach-garden-oath-1592-v2.jpg- 桃園結義 (The Oath in the Peach Garden), woodcut from Yu Xiangdou’s 新刊京本校正演義全像三國志傳評林, Jianyang, 1592 (Waseda University Library); scan from Wikimedia Commons, cropped inside its frame and clear of what was left of it, cleaned and toned to the page’s ink and paper (Yu Xiangdou (publisher), anonymous block cutter, 公有领域)
做法
#1 · 把页面转四分之一圈,在右侧装订
代码见上文的简短回答。layout.writingMode: 'vertical-rl'把每一页都当作顺时针转了四分之一圈的横排页面来排:文字流的一行就是一列字,从右向左读,断行、两端对齐和两字缩进都沿着这一列进行(竖排)。page.binding保持'auto',竖排书会因此在右侧装订:第1页仍是奇数页,但它是一个左页,mirror: true把它的内页边距left放到了右边(装订)。工具包里的showBook按书打开的样子排列跨页,先是单独的第1页,然后是[3 | 2];PDF用/Direction /R2L请阅读器采用同样的顺序,Acrobat会照办,Chrome的阅读器则忽略它。
字符网格把版心设为竖向40个10.5 pt的字、横向16行、行距19 pt,即148.2 × 107.2 mm。page里的页边距是最小值:网格把每一对页边距同样放大,天头到33.9 mm,地脚到27.9 mm,订口17.4 mm,切口23.4 mm。locale: 'zh-Hant'让东亚设置采用台湾的取值:每个标点占一个全角,居于字格中央,标点之间不挤压。trad-chinese-informal把页码印成一到九,第{1:一}回给本回编号(编号)。
#2 · 把回目排成两行并加线
// In the flow frame x runs down the column and y across the page, right to left, so a
// 'horizontal' rule is a vertical line on the sheet: three of them rule the title columns.
const [TITLE, PITCH] = [13.5, 1.5 * LEAD]; // pt: the couplet's size and its column pitch
const rule = (n) => ({ kind: 'rule', id: `rule-${n}`, direction: 'horizontal',
thickness: pt(0.5), color: col('vermilion'),
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { y: pt(LEAD + n * PITCH) }, size: { width: 'fill' } } });
const title = (id, content, x, family, weight) => ({ kind: 'text', id, content,
fontFamily: family, fontWeight: weight, fontSize: pt(TITLE), lineHeight: PITCH / TITLE,
color: col('ink'), align: 'left', // the head of the column
placement: { anchor: { to: 'container', edge: 'top-left' },
offset: { x: pt(x), y: pt(LEAD) } } }); // a line of PITCH, centred between two rules
const opener = {
enabled: true,
minHeight: cols(5), // a blank column, the two title columns, a blank one: 5 × 19 pt
slot: { elements: [
rule(0), rule(1), rule(2),
title('number', '{number}', 2 * BODY, SONG, 700), // 第一回, two characters down
// The couplet's two halves, broken by the \\ in the heading, start level with each other.
title('couplet', '{titleText}', 2 * BODY + 4 * TITLE, KAI, 400),
] },
};
竖排页面上的标题设计在文字流坐标系中排:x从版心顶端沿列向下,y从页面右边缘横向延伸。因此一条'horizontal'的线在纸面上是一条竖线,与一列等长。三条0.5 pt的线框住两列标题,两列相距28.5 pt,是正文行距的1.5倍。每一列是一行28.5 pt高的文字,字符位于它的中间,正好在两条线之间。{number}用Noto Serif TC Bold在低两格处印出第一回;{titleText}用LXGW WenKai TC在它后面隔一个字印出对联。标题写作# 宴桃園豪傑三結義 \\ 斬黃巾英雄首立功,强制换行让下半联从下一列开始,与上半联齐平。minHeight预留五列19 pt,所以正文从它的网格上开始(通栏与高级设计)。在把标题读作一行的地方,即书眉和PDF书签里,这个换行会变成一个全角空格。
#3 · 把书眉和页码排在切口一侧
const foreEdge = (id, content, parity, edge, y, pages) => ({
kind: 'text', id, content, parity, pages, writingMode: 'vertical-rl',
fontFamily: HEI, fontSize: pt(8.5), color: col('muted'), overflow: 'clip',
placement: { anchor: { to: 'outer', edge }, offset: { y: em(y) } },
});
const header = { elements: [
foreEdge('book', '{title}', 'even', 'top', 4, 'body'), // 三國演義 on the right-hand page
foreEdge('chapter', '{chapterNumber} {chapterTitle}', 'odd', 'top', 4, 'body'),
foreEdge('folio', '{pageNumber}', 'all', 'bottom', -5, 'all'), // on openers too
] };
台湾的竖排书常把书眉和页码竖排在外页边距里。writingMode: 'vertical-rl'让一个页眉元素在纸面上从上到下排,anchor.to: 'outer'把它放在外页边距里;书在右侧装订时,奇数页的外页边距在左边,偶数页的在右边(竖排文本元素)。偏移量以元素自身8.5 pt的em为单位,约为正文字号的80 %:书眉从版心顶端往下四个字开始,页码在版心底端往上五个字处结束。parity把三國演義放在右页,把回目放在左页。pages: 'body'让两种书眉都不出现在开篇页上,而开篇页保留页码。
#4 · 把插图页放在本回之前
const none = { elements: [] };
// A point of a page design in the flow frame: mm down the column, mm leftward across the
// page from the right edge of the type area.
const at = (down, across) => ({ anchor: { to: 'container', edge: 'top-left' },
offset: { x: mm(down), y: mm(across) } });
// The title slip (題簽), 96 × 22 mm: its axis, 55 mm in from the right of the type area, is
// the axis of the page, and of the imprint under it.
const SLIP = { down: 10, across: 44, long: 96, wide: 22 };
const AXIS = SLIP.across + SLIP.wide / 2;
const slip = (id, inset, thickness) => ({ kind: 'box', id,
placement: { ...at(SLIP.down + inset, SLIP.across + inset),
size: { width: mm(SLIP.long - 2 * inset), height: mm(SLIP.wide - 2 * inset) } },
style: { borderColor: col('vermilion'), borderWidth: pt(thickness) } });
const RUN = (4 * 40 + 3 * 10) * PT; // 三國演義 down the slip: four 40 pt characters, 3 gaps
const titlePage = {
id: 'title', numbered: false, toc: false, span: 'page', header: none,
breakBefore: { enabled: true, parity: 'any' },
footer: { elements: [{ kind: 'text', id: 'imprint', content: '{attr.colophon}',
fontFamily: ROMAN, fontSize: pt(6.5), lineHeight: 1.4, color: col('muted'),
// In the edition's language, set across and centred on the axis: the box runs from the
// left of the type area (16 columns) as far past the axis. Each \n in the attribute
// starts a line, and *…* sets the book's title in italic.
inlineMarks: true, overflow: 'wrap', align: 'center',
placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(4) },
size: { width: mm(2 * (16 * LEAD * PT - AXIS)) } } }] },
advancedDesign: { enabled: true, minHeight: cols(16), slot: { elements: [
slip('slip', 0, 1.4), slip('slip-in', 1.2, 0.4), // a heavy and a light vermilion rule
{ kind: 'text', id: 'book', content: '{titleText}', fontFamily: SONG, fontWeight: 700,
fontSize: pt(40), lineHeight: 1, letterSpacing: pt(10), color: col('ink'),
placement: at(SLIP.down + (SLIP.long - RUN) / 2, AXIS - 20 * PT) }, // 40 pt line on the axis
{ kind: 'text', id: 'author', content: '{author} 著', fontFamily: KAI, fontSize: pt(12),
color: col('ink'), placement: at(52, 72) },
{ kind: 'text', id: 'editor', content: '{attr.editor}', fontFamily: KAI, fontSize: pt(12),
color: col('ink'), placement: at(52, 80) },
] } },
};
// The woodcut, 138 mm tall in a double frame (四周雙邊), hangs from the top right corner of
// the type area, and its caption runs down the column on its left. In the flow frame a
// box's width runs down the page: the picture's width is its height on the sheet, and it
// stands upright in the canvas, the HTML and the PDF.
const PLATE = { right: 8.3, top: 5.1, h: 138, w: (138 * 806) / 1427 }; // mm
const frame = (id, inset, thickness) => ({ kind: 'box', id,
placement: { ...at(PLATE.top - inset, PLATE.right - inset),
size: { width: mm(PLATE.h + 2 * inset), height: mm(PLATE.w + 2 * inset) } },
style: { borderColor: col('ink'), borderWidth: pt(thickness) } });
const plate = {
id: 'plate', numbered: false, toc: false, span: 'page', header: none, footer: none,
breakBefore: { enabled: true, parity: 'any' },
advancedDesign: { enabled: true, minHeight: cols(16), slot: { elements: [
{ kind: 'image', id: 'woodcut', resourceId: 'peach-garden',
placement: { ...at(PLATE.top, PLATE.right), size: { width: mm(PLATE.h), height: 'auto' } } },
frame('inner', 1.6, 0.4), frame('outer', 2.8, 1.4),
{ kind: 'text', id: 'caption', content: '{titleText}', fontFamily: HEI, fontSize: pt(9),
color: col('ink'), placement: at(PLATE.top - 2.8, PLATE.right + PLATE.w + 7) },
{ kind: 'text', id: 'note', content: '{attr.note}', fontFamily: KAI, fontSize: pt(8),
color: col('muted'), placement: at(PLATE.top - 2.8, PLATE.right + PLATE.w + 12) },
] } },
};
const resources = [{
id: 'peach-garden', typeId: 'figure', kind: 'bitmap', createdAt: 0, updatedAt: 0,
bitmap: { fileId: 'peach-garden.jpg', format: 'jpeg', width: 806, height: 1427 },
caption: '桃園結義',
altText: '桃園結義圖:劉備、關羽、張飛立於祭桌前,桌上香爐燭臺與三杯酒,旁有烏牛白馬。',
}];
书名页和插图页是两个一级标题,各有自己的样式:# 三國演義 {style="title" …}和# 桃園結義 {style="plate" …}。numbered: false把它们排除在编号之外,所以本回仍是第一回;它们自己的header为空,替换了切口书眉。本回的breakBefore要求从奇数页开始,也就是第3页,它所在的跨页右边是插图:读者先看到图,再看到正文,与绣像本(繡像)一样(标题样式)。页码也不出现在这两页上。中文编辑从正文的第一页开始编页码,所以在本回标题前面加一行:::numbering{startAt=1},让第3页重新从一开始计数(:::numbering);书名页和插图页在奇偶计算中仍算作两页,阅读器和PDF照样把它们标为一和二(下面的一个变化把它们区分开)。
三國演義在题签上居中:RUN是四个40 pt的字加上它们之间三个10 pt间隔的长度,不含最后一个字之后的字距。书名页的页脚在底部横排版权说明,用的是本版本的语言,取自标题的colophon属性。Noto Serif TC没有斜体,所以版权说明用Source Serif 4排:inlineMarks: true读取书名两边的星号,属性里的每个\n另起一行,让各行按意思断开(文本元素)。这个框的宽度是版心左边到题签中轴距离的两倍,这样每一行的中心都位于三國演義的正下方。插图页的设计把木刻和它的双线框挂在版心的右上角,并把图题分两列竖排在它的左侧。在文字流坐标系中,框的宽度沿页面向下延伸,所以图片的width就是它在纸面上的高度;它在Canvas、HTML和PDF里都是正立的,带标签的PDF会把它读作一幅带替代文字的图。
#5 · 每种字体只加载它要排的字
// Fontsource cuts a Chinese face into about a hundred files; loadCjkFonts fetches those
// that hold the characters it is given (gotcha: cjk-fonts-slices). vertical: true loads the
// face again with its vertical punctuation forms, for the canvas.
const heads = markdown.match(/^# .*$/gm).join('').replace(/\{[^}]*\}/g, ''); // no attributes
const attr = (key) => markdown.match(new RegExp(`${key}="([^"]*)"`))?.[1] ?? '';
const verse = markdown.match(/:::paragraphs\{style="verse"\}[\s\S]*?\n:::/g).join('');
await loadFonts(FONTS, markdown); // the Latin files: the imprint
await loadCjkFonts({ [SONG]: ['400'] }, markdown, { vertical: true });
await loadCjkFonts({ [SONG]: ['700'] }, '三國演義第一回'); // no punctuation: no vertical twin
await loadCjkFonts({ [KAI]: ['400'] }, `${heads}${verse}${attr('editor')}${attr('note')}羅貫中著`,
{ vertical: true });
await loadCjkFonts({ [HEI]: ['400'] }, `${heads}第回一二三四五六七八九十`, { vertical: true });
这本书用三种字体:正文用Noto Serif TC(宋),对联和诗词用LXGW WenKai TC(楷),切口用Noto Sans TC(黑)。Fontsource把中文字体的每个字重拆成大约一百个文件提供,每个文件覆盖一段字符范围,loadCjkFonts只取含有所给文本的那些文件(中文、日文和韩文字体)。正文字体拿到整回文字,取了67个文件;楷体拿到标题和诗词,取了25个,黑体取了15个,粗体取了4个。粗体只排七个字,没有标点,所以不加载竖排字形。版权说明用的Source Serif 4和其他拉丁字体一样通过loadFonts加载,包括正体和斜体。renderToPdf接收cjkPdfProvider,它把同样的文件以子集形式嵌入,还接收木刻图所需的imageBytes。
完整食谱
// ═══ Postext Cookbook · Nº 075 · A vertical Chinese novel, bound on the right ════════
// https://postext.dev/en/cookbook/vertical-novel-right-bound
// Code: MIT · Text: 三國演義 ch. 1, zh.wikisource (CC BY-SA 4.0) · Plate: woodcut, 1592 (PD)
// Fonts: Noto Serif TC, LXGW WenKai TC, Noto Sans TC, Source Serif 4 (OFL) · Needs postext ≥ 1.25.0
import {
buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage, loadVerticalAlternates,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the frame; the novel is Chinese in both editions
const RECIPE = 'vertical-novel-right-bound';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: black ink, one vermilion, the paper the plate was toned to
const palette = {
ink: '#2a221d', // the text, and the woodcut's lines
vermilion: '#a3301f', // 朱: the ruled columns of the opener, the title slip
muted: '#6f655c', // fore-edge heads, folios, the imprint
paper: '#fbf8f1', // the page; the plate's paper was toned to this value
};
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.vermilion, model: 'hex' } },
];
// #endregion
const [SONG, KAI, HEI] = ['Noto Serif TC', 'LXGW WenKai TC', 'Noto Sans TC']; // 宋, 楷, 黑
const ROMAN = 'Source Serif 4'; // the imprint: Noto Serif TC has no italic
const [BODY, LEAD] = [10.5, 19]; // pt: 五號 text on a column pitch of 1.8 em
const cols = (n) => pt(n * LEAD); // n columns across the page
const PT = 25.4 / 72; // mm in a point
// #region answer: vertical text on a 25開 page, bound on the right, 40 characters × 16 columns
// 'vertical-rl' turns the flow a quarter turn: lines run down, columns from right to left,
// and page.binding 'auto' becomes 'right', so page 1 is a left-hand page and the spreads
// read [3 | 2]. The grid sets the type area in characters; the margins are minimums it
// grows. zh-Hant resolves to Taiwan's rules: every mark full width and centred in its cell.
const page = {
sizePreset: 'custom', width: mm(148), height: mm(210), dpi: 150,
backgroundColor: col('paper'),
// 天頭 above 地腳; left is the spine side (the right edge of a left-hand page).
margins: { top: mm(32), bottom: mm(26), left: mm(16), right: mm(22), mirror: true },
pageNumbering: { format: 'trad-chinese-informal' }, // folios 一, 二 … 九, from the chapter
};
const layout = { layoutType: 'single', writingMode: 'vertical-rl' };
const cjk = { grid: { enabled: true, charsPerLine: 40, linesPerPage: 16 } };
const chapter = {
level: 1, numberingTemplate: '第{1:一}回', numberSeparator: ' ', // 第一回 宴桃園…
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#逐位写出页码
cjk-decimal每一位数字写一个数字字。本回在页码九结束,这时两种格式结果相同;从正文第十页起,十和十一会写成一〇和一一。
- pageNumbering: { format: 'trad-chinese-informal' }, // 页码一、二……九,从本回开始
+ pageNumbering: { format: 'cjk-decimal' }, // 页码一、二……九、一〇、一一#把前面几页单独标记
书名页和插图页不印页码,但阅读器和PDF把它们标为一和二,与正文的头两页相同;如果前面几页改用罗马数字标记,把中文数字移到:::numbering那一行,PDF就会按i、ii、一、二……计数。
- pageNumbering: { format: 'trad-chinese-informal' }, // 页码一、二……九,从本回开始
+ pageNumbering: { format: 'lower-roman' }, // i、ii:书名页和插图页-:::numbering{startAt=1}
+:::numbering{format="trad-chinese-informal" startAt=1}#横排本回
大陆的惯例是把同类章回横排,左侧装订,用简体字和开明式标点:28 × 28字格上的中文小说页。
常见问题
易错点
用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,并在消息中给出这个字符;在页面上,它会用后备字体印出。在示例中恢复繁体字形,并在出处说明中注明。 中日韩字体 →
致谢
- 文本
- 三國演義 (Romance of the Three Kingdoms), chapter 1, Mao Zonggang recension (about 1679); Wikisource transcription, revision 2583915, with one character corrected (颙 → 顒) · Luo Guanzhong; transcription by Wikisource editors · CC BY-SA 4.0
- 图片
- 桃園結義 (The Oath in the Peach Garden), woodcut from Yu Xiangdou’s 新刊京本校正演義全像三國志傳評林, Jianyang, 1592 (Waseda University Library); scan from Wikimedia Commons, cropped inside its frame and clear of what was left of it, cleaned and toned to the page’s ink and paper · Yu Xiangdou (publisher), anonymous block cutter · 公有领域
- 字体
- Noto Serif TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1) · Source Serif 4 (SIL OFL 1.1)


