简单来说
两篇短篇小说,按日本全集的样子排:文字竖排在上下叠放的两栏里,每篇从左页开始,篇名贯穿整个页高,最后一页不拉平。
成品一览
一卷全集的七页,A5页面,右侧装订:芥川龍之介的《蜘蛛の糸》和《尾生の信》,排成上下两栏(二段組),每栏竖向25字,横向21行,用9 pt的Noto Serif JP,两栏之间一条细线。每篇从奇数页也就是左页开始,20 pt的篇名从上到下贯穿两栏,作者名靠近底部;页码从第211页接着往下编。一、二、三各节的节号在本栏内占三行。一篇结束时,最后一页任文字自然落下,日文叫成り行き(nariyuki):第214页上,这一篇连同日期在上栏结束,离排满只差一行,下栏空着。分栏竖排的中文报纸见Nº 084,横跨两栏的横排章首页见Nº 017。
这道食谱解答
- 怎样让章标题横跨页面,下面的正文分两栏排?
- 怎样强制分页或分栏,并让每章都从右页开始?
- 怎样按字数设定版心,每行多少字、每页多少行?
简短回答
// On a vertical page two columns are two tiers (段), filled from the upper right: the
// gutter is the gap between them and the column rule a hairline across the page. The grid
// counts characters down one tier, so each tier is exactly 25 em long and the gutter 2 em.
const layout = {
layoutType: 'double', writingMode: 'vertical-rl', // binding 'auto' becomes 'right'
gutterWidth: pt(2 * BODY),
columnRule: { enabled: true, color: col('rule'), lineWidth: pt(0.4) },
};
const cjk = { grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES } };
// 成り行き (nariyuki): the text fills the upper tier across the whole page before the
// lower one, and a work's last page is not levelled: its lower tier ends where the text
// does. trailing: false is that choice (vertical tiers are not balanced by default either).
const balancing = { trailing: false };
// Each work opens on an odd page, the left-hand one in a book bound on the right, with a
// blank page before it when the last work ended on an odd page.
const work = { level: 1, span: 'page', breakBefore: { enabled: true, parity: 'odd' } };
// 一 二 三 take three lines of their tier (3行取り), eight characters down.
const section = { level: 2, fontSize: pt(11), fontWeight: 600, lineSpan: 3, indent: em(8) };
用料
做法
#1 · 转了四分之一圈的两栏就是上下两栏
代码见上文的简短回答。在设了writingMode: 'vertical-rl'的页面上,layoutType: 'double'把两栏叠放:先从右往左排满上栏,再排下栏,栏间距就是两栏之间的那条带(竖排)。字符网格按一栏竖向的字数计数,所以每栏是25个9 pt的字,栏间距取整为两个字;21行、行距15.75 pt,横向占148 mm宽页面中的116.7 mm。两栏之间的线横贯页面,0.4 pt,暖灰色。
Postext的齐底功能会让一篇最后一页的两栏在同一行结束,中文报纸和大多数欧洲双栏书就是这样收章的。分栏的日文书让文字自然落下:上栏排满全页之后才开始下栏。balancing.trailing: false就是这个选择;竖排的分栏默认完全不齐底,除非用enabled: true打开齐底功能(各栏齐底)。
#2 · 让篇名贯穿两栏
// A page-span heading is laid out across the whole height of the page, both tiers and the
// gutter, in the flow frame: x runs down the page, y across it leftwards from the right
// edge of the type area. The design reserves seven lines (七行取り); the tiers start after it.
const at = (down, across) => ({ anchor: { to: 'container', edge: 'top-left' },
offset: { x: pt(down), y: pt(across) } });
const TITLE = 20; // pt
const opener = { enabled: true, minHeight: lines(7), slot: { elements: [
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: MINCHO, fontWeight: 600,
fontSize: pt(TITLE), lineHeight: 1, letterSpacing: pt(TITLE / 2), color: col('ink'),
placement: at(5 * BODY, 2.5 * LEAD - TITLE / 2) },
{ kind: 'text', id: 'author', content: '{author}', fontFamily: MINCHO, fontSize: pt(10.5),
letterSpacing: pt(3), color: col('ink'),
placement: at(HEIGHT - 5 * 10.5 - 4 * 3 - 3 * BODY, 4.5 * LEAD - 10.5 / 2) },
] } };
带span: 'page'的标题级别横跨整个页高排出,包括两栏和栏间距,位于文字流的开头,在竖排页面上就是右边;两栏从它的设计所预留的七行之后开始。这样的标题总是另起一页,breakBefore.parity: 'odd'让这一页是左页:《蜘蛛の糸》在偶数页第214页结束,所以《尾生の信》从第215页开始,中间没有空白页(通栏与高级设计)。设计中x沿页面向下,y从版心右边缘横向延伸;作者名从下栏底端往上三字处放置。
#3 · 节号在本栏内占三行
第二级标题设lineSpan: 3和indent: em(8),把一、二、三排在本栏内低八字、三行宽的带里,与青空文库文本的标法一致(八字下げ,中見出し),这样节号后面的正文仍与旁边一栏的行对齐(按级别覆盖)。结束各篇的日期(大正七年四月十六日)用:::paragraphs{align=end endIndent=1}在本栏内离底边空一字(地から一字上げ);青空文库转换脚本把它们写成aozora-end1样式,让它们与底边齐平,围栏上的属性再加上空出的那一字。
#4 · 卷名和篇名排在切口
// anchor 'outer' is the fore-edge: the left margin of an odd page and the right one of an
// even page in a book bound on the right. The volume's name on the right-hand page, the
// work on the left; the folios count on from the volume's page 211.
const foreEdge = (id, content, parity, edge, y, extra = {}) => ({
kind: 'text', id, content, parity, pages: 'body', writingMode: 'vertical-rl',
fontFamily: GOTHIC, fontSize: pt(7), letterSpacing: pt(1), color: col('muted'),
overflow: 'clip', placement: { anchor: { to: 'outer', edge }, offset: { y: em(y) } },
...extra,
});
const header = { elements: [
foreEdge('volume', '{title}', 'even', 'top', 2),
foreEdge('work', '{chapterTitle}', 'odd', 'top', 2),
// The folio in Arabic digits, set across the margin: down the fore-edge they would lie
// on their side.
foreEdge('folio', '{pageNumber}', 'all', 'bottom', -1, { pages: 'all', writingMode: undefined,
letterSpacing: pt(0.5) }),
] };
const none = { elements: [] };
// The first work's opening page carries the colophon across the foot, in the edition's
// language (a style's footer serves every page of its section: gotcha style-header-whole-section).
const first = { id: 'first', footer: { elements: [{ kind: 'text', id: 'colophon', pages: 'opener',
content: '{attr.colophon}', fontFamily: GOTHIC, fontSize: pt(5.5), lineHeight: 1.45,
color: col('muted'), overflow: 'wrap', align: 'center',
placement: { anchor: { to: 'page', edge: 'bottom' }, offset: { y: mm(-6) },
size: { width: mm(118) } } }] } };
anchor.to: 'outer'把柱放在切口一侧的页边距里,右页是卷名芥川龍之介集,左页是篇名;pages: 'body'让两者都不出现在一篇开始的页面上(竖排文本元素)。页码用阿拉伯数字横排在页边距里,很多全集这样印:沿切口竖排时,三位数字会躺倒。pageNumbering.startAt: 211按这一卷的页码编号。第一篇的标题样式用pages: 'opener'带上版权说明,因为一个样式的页脚会出现在其所在一节的每一页上。
完整食谱
// ═══ Postext Cookbook · Nº 118 · A Japanese story in two tiers, its title across both ═══
// https://postext.dev/en/cookbook/two-tier-tankobon
// Code: MIT · Text: 芥川龍之介『蜘蛛の糸』『尾生の信』, Aozora Bunko 92, 24 (PD) · Pictures: none
// Fonts: Noto Serif JP, Noto Sans JP (SIL OFL 1.1) · Needs postext ≥ 1.25.0
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 colophon; the stories are Japanese in both
const RECIPE = 'two-tier-tankobon';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink, one deep indigo, a warm book paper
const palette = {
ink: '#1d1b19', // the text
indigo: '#2f3d63', // 藍: the cloth of the case; the engine's defaults
rule: '#8c857b', // the hairline between the two tiers
muted: '#655e56', // the hashira and the folios
paper: '#fcfaf4',
};
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.indigo, model: 'hex' } },
];
// #endregion
const [MINCHO, GOTHIC] = ['Noto Serif JP', 'Noto Sans JP'];
const [BODY, LEAD, CHARS, LINES] = [9, 15.75, 25, 21]; // pt, pt: 2 段 × 25字 × 21行
const HEIGHT = 2 * CHARS * BODY + 2 * BODY; // pt: two tiers and a gutter of two characters
const lines = (n) => pt(n * LEAD); // n lines across the page
// #region answer: two tiers of 25 characters, the last page of a work left as it falls
// On a vertical page two columns are two tiers (段), filled from the upper right: the
// gutter is the gap between them and the column rule a hairline across the page. The grid
// counts characters down one tier, so each tier is exactly 25 em long and the gutter 2 em.
const layout = {
layoutType: 'double', writingMode: 'vertical-rl', // binding 'auto' becomes 'right'
gutterWidth: pt(2 * BODY),
columnRule: { enabled: true, color: col('rule'), lineWidth: pt(0.4) },
};
const cjk = { grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES } };
// 成り行き (nariyuki): the text fills the upper tier across the whole page before the
// lower one, and a work's last page is not levelled: its lower tier ends where the text
// does. trailing: false is that choice (vertical tiers are not balanced by default either).
const balancing = { trailing: false };
// Each work opens on an odd page, the left-hand one in a book bound on the right, with a
// blank page before it when the last work ended on an odd page.
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#让末页齐底
打开齐底功能,每篇的最后一页就会切平:第214页上栏10行、下栏10行结束,这是分栏的中文书或欧洲书收尾的方式。在字符网格上,齐底功能只增加整行,每个字都留在自己的格子里。
-const balancing = { trailing: false };
+const balancing = { enabled: true }; // the closing band is cut level#每篇从下一页开始
parity: 'any'让一篇从紧接着的下一页开始,不论奇偶,杂志和收录极短篇目的选集这样做。
-const work = { level: 1, span: 'page', breakBefore: { enabled: true, parity: 'odd' } };
+const work = { level: 1, span: 'page', breakBefore: { enabled: true, parity: 'any' } };#只排一栏
长篇小说和文库本只排一栏,没有栏间距;Nº 117就是这样排一本文库本的。
常见问题
易错点
日文文本标记为'ja',不要用zh-Hans或LANG
食谱的版本是en和es,但日文示例在两个版本里都是日文:`locale: LANG`会把它标记为英文或西班牙文,中文标记则会按中文规则排它(开明式标点、小假名可以出现在行首、图代替図、PDF中用中文字形)。postext 1.30起,这个标记也是文字成形所用的语言(测量、绘制和嵌入都按它进行),所以'ja'以外的标记给出的不是日文字形(中文标记给出中文字形),断行的位置也不同。写'ja':它选用日本地区(JLReq断行和标点、芝麻着重号、振假名的分布、図和表标签),并关闭断词。lint会让带假名却标记为zh或ko的文本失败。 日文禁则处理 →
易错点
通栏标题总是开启新页
标题级别或样式设了span: 'page'的标题,会作为章首页排在页面顶部,不管它有没有breakBefore。放在其他文字之后,或同一页另一个章首页之后,它都会移到下一页,当前页余下部分留空。报头下横跨两栏(或竖排页面两层)的通栏大标题,要放进章首页自己的设计里,与报头并列;或者放进:::callout{span="page"}框中,作为不设span的标题,newspaper-front-page就是这样排通栏标题的。 设计过的章首页 →
易错点
中文字体通过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]。 右翻书 →
致谢
- 文本
- 芥川龍之介「蜘蛛の糸」 (The Spider’s Thread, 1918); Aozora Bunko card 92, from 「芥川龍之介全集2」 (Chikuma Bunko, 1986), input 平山誠 and 野口英司, proofreading もりみつじゅんじ, converted with aozora.py · Akutagawa Ryūnosuke; Aozora Bunko volunteers · 公有领域
- 芥川龍之介「尾生の信」 (Bisei’s Faith, 1920); Aozora Bunko card 24, from 「芥川龍之介全集3」 (Chikuma Bunko, 1986), input j.utiyama, proofreading かとうかおり, converted with aozora.py; the rule before the coda shortened to fit a tier · Akutagawa Ryūnosuke; Aozora Bunko volunteers · 公有领域
- 字体
- Noto Serif JP (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1)


