跳到主要内容
食谱编号81

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

竖排中的日期与缩略词直立

两份1912年的建国文献竖排、右侧装订:一两位数字不加标记就在一格内直立,其余的用:tcy和:upright标出。

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

页码一 · 第1页,共7页

  • 英文样例:尚无中文版本
  • 成品尺寸184 × 260 mm
  • 1栏
  • Noto Serif TC 12/21
  • LXGW WenKai TC
  • Noto Sans TC
  • 7页
  • 难度
  • Postext 1.65.0
  • 排版用时59 ms
  • 181行代码

简单来说

两篇1912年的中文文献,竖排印刷。示例演示在竖排文字里,日期、数字和外文字母怎样摆放才好读。

成品一览

一本七页的读本,收录中华民国的两份建国文献:孙文1912年1月1日就职时发布的宣言书,以及3月11日公布的临时约法的前两章。页面为184 × 260 mm,竖排,右侧装订。文献本身保留原有的汉字数字,如民國元年三月十一日。题解和注释用楷体,其中的公历日期、数量和号数用阿拉伯数字,食谱处理的正是这些数字:10月10日每个数在一格内直立,1912和Sun Yat-sen横躺,民國115年把三位数挤进一格,ROC的字母逐个直立堆叠。外围是双线框住的朱红封面、每份文献开篇处的朱红色带,以及切口一侧带汉字页码的书眉。

这道食谱解答

  • 怎样在竖排文字里让日期和数字直立?
  • 怎样把中文书排成竖排、右侧装订?
  • 怎样按字数设定版心,每行多少字、每页多少行?

简短回答

script.js · 第41–50行在完整代码中
const layout = { layoutType: 'single', writingMode: 'vertical-rl' }; // binding 'auto': right
const cjk = {
  // 10月10日: each number of up to two digits stands upright in one cell (tate-chu-yoko);
  // 1912 and Sun Yat-sen stay on their side, as clreq sets long numbers and Latin words.
  uprightDigits: 2,
  // The type area in characters: 44 down each line, 19 lines to the page.
  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: 19 },
};
// By hand, in the Markdown: 民國:tcy[115]年 puts three digits in one cell, :upright[ROC]
// stands each letter of an acronym upright, :sideways[…] turns any run with the line.

用料

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

做法

#1 · 短数字交给排版设置

代码见上文的简短回答。设置cjk.uprightDigits: 2后,竖排中每一段一两位的数字都在一个全角格内直立,两位数字并排:10月10日、第35號、7章56條都不需要标记。更长的数字像拉丁词一样整体横躺,clreq对四位数字也是这样处理的,所以1912和1644转过四分之一圈,顺行向下读。要让三位数直立,就得加标记:民國:tcy[115]年把115挤进一个全角格。:upright[ROC]让每个字母各占一格,上下堆叠,行也不会在其中断开(竖排中的数字)。

第4页,注释:10月10日和2月12日直立,1911和Sun Yat-sen横躺,268和115用:tcy挤入一格,ROC用:upright逐字堆叠。

1912年的原文保持原样。编者的注释按台湾地区的数字用法书写,即行政院2004年的《公文書橫式書寫數字使用原則》:日期、序号和数量用阿拉伯数字(1912年3月8日、第35號、7章56條),专有名词、惯用语和概数保留汉字数字(東三省、四萬萬、四億),农历日期辛亥年八月十九日也是如此。注释引用文献中的标题或词语时,保留原来的写法,如第一章、二十二行省。这些规则是为横排公文制定的;一旦竖排,其中的阿拉伯数字就是食谱需要让它直立的那些。

#2 · 每份文献以右侧的色带开篇

script.js · 第54–78行在完整代码中
// The margins are minimums: the grid centres the 44 characters (186.3 mm) between them,
// so the type area starts HEAD mm down the sheet. The band's title starts there too.
const HEAD = MARGIN.top + (TRIM.h - MARGIN.top - MARGIN.bottom - LINE) / 2;
const BAND = 42; // mm from the right trim edge: where a reader of vertical text starts
const onBand = { color: col('paper'), overflow: 'wrap' };
// In the flow of a vertical page x runs down the sheet and y leftward from its right edge.
const at = (x, y, extra = {}) => ({ anchor: { to: 'page', edge: 'top-left' },
  offset: { x: mm(x), y: mm(y) }, ...extra });
const opener = {
  enabled: true,
  minHeight: mm(BAND - 15), // past the side margin (21.6 mm), 6 mm of paper before the text
  slot: { elements: [
    { kind: 'box', id: 'band', style: { backgroundColor: col('seal') },
      placement: { anchor: { to: 'bleed', edge: 'top-left' }, size: { height: mm(BAND) } } },
    { kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: HEI,
      fontWeight: 700, fontSize: pt(34), lineHeight: 1.2, letterSpacing: pt(4), align: 'left',
      placement: at(HEAD, 8) },
    { kind: 'text', id: 'latin', content: '{attr.latin}', ...onBand, fontFamily: HEI,
      fontSize: pt(9), lineHeight: 1.6, align: 'left', placement: at(HEAD, 25) },
    // The date ends where the lines of text end: align 'right' is the foot of a vertical line.
    { kind: 'text', id: 'date', content: '{attr.date}', ...onBand, fontFamily: HEI,
      fontWeight: 500, fontSize: pt(13), lineHeight: 1.2, align: 'right',
      placement: at(HEAD, 24, { size: { width: mm(LINE) } }) },
  ] },
};

在竖排流中,页面的“顶端”是纸张的右边缘,阅读从那里开始。因此,锚定在出血框顶端的标题设计就成了沿右边缘而下的一条色带,它的size.height是它在纸上的宽度。偏移量也随排版方向转向:x沿纸面向下量,y向左量。网格把版心居中放在页边距之间,HEAD重复了同一算式,所以标题与每行正文的第一个字齐平。align: 'right'把日期放在所在行的底端,也就是正文各行结束的位置;cjk.uprightDigits对设计中的文字同样生效:3月11日的11和正文里一样在一格内直立。这条色带就是出血色带上的章首页里的那条,转了四分之一圈。

标题设计没有奇偶之分,所以色带总是沿纸张右边缘而下。第2页是右页,那条边是切口;第5页在右侧装订的书里是左页,那条边是订口,标题从离折线8 mm处开始,落在21.6 mm的内页边距之内。骑马订的读本能摊得够平,这不成问题。如果是锁线或胶装的书,用breakBefore.parity: 'even'让每份文献都从右页开始,第5页就会留空。

第2页:标题从版心顶端开始,日期在色带底部,题解中晚上10時的10和同月29日的29直立。

#3 · 把书眉放在切口一侧

script.js · 第82–90行在完整代码中
const foreEdge = (id, content, edge, y) => ({
  kind: 'text', id, content, writingMode: 'vertical-rl', pages: 'body', align: 'left',
  fontFamily: HEI, fontSize: pt(9.6), color: col('muted'), overflow: 'clip',
  placement: { anchor: { to: 'outer', edge }, offset: { y: em(y) } },
});
const header = { elements: [
  foreEdge('head', '{chapterTitle}', 'top', 4), // four characters below the type area
  foreEdge('folio', '{pageNumber}', 'bottom', -5), // ends five characters above its foot
] };

anchor.to: 'outer'指远离订口的页边距,所以在右侧装订的书里,书眉在右页沿左边缘排,在左页沿右边缘排。书名比版心顶端低四个字,页码在距版心底端五个字处结束,二者都竖排,字号为正文的80 %(竖排文本元素)。pageNumbering.format: 'trad-chinese-informal'把页码印成三、四、六、七,pages: 'body'让两个开篇页不出现书眉。

#4 · 用页宽设计让封面出血

script.js · 第94–119行在完整代码中
const frame = (id, inset, width) => ({ kind: 'box', id,
  style: { borderColor: col('tint'), borderWidth: pt(width) },
  placement: at(inset, inset, { size: { width: mm(TRIM.h - 2 * inset),
    height: mm(TRIM.w - 2 * inset) } }) });
const coverLine = (id, content, y, align) => ({ kind: 'text', id, content, ...onBand,
  fontFamily: HEI, fontWeight: 500, fontSize: pt(18), lineHeight: 1.2, align,
  placement: at(HEAD, y, { size: { width: mm(LINE) } }) });
const cover = {
  id: 'cover', numbered: false, toc: false, runningChapter: false,
  span: 'page', // a page-wide design is not cut at the foot of the column: the field bleeds
  header: { elements: [] }, footer: { elements: [] },
  advancedDesign: { enabled: true, slot: { elements: [
    { kind: 'box', id: 'field', style: { backgroundColor: col('seal') },
      placement: { anchor: { to: 'bleed', edge: 'top-left' }, size: { height: mm(TRIM.w) } } },
    frame('rule-outer', 11, 1.6), frame('rule-inner', 13, 0.5), // 文武線: thick, then thin
    { kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: HEI,
      fontWeight: 700, fontSize: pt(56), lineHeight: 1.1, letterSpacing: pt(5.6), align: 'left',
      placement: at(HEAD, 26) },
    { kind: 'text', id: 'latin', content: '{attr.latin}', ...onBand, fontFamily: HEI,
      fontSize: pt(11), lineHeight: 1.4, align: 'left', placement: at(HEAD, 51) },
    coverLine('first', '臨時大總統宣言書', 104, 'left'),
    coverLine('first-date', '1912年1月1日', 104, 'right'),
    coverLine('second', '中華民國臨時約法', 118, 'left'),
    coverLine('second-date', '1912年3月11日', 118, 'right'),
  ] } },
};

栏内的标题设计在栏底被截断,而竖排页面的栏底是左页边距:锚定在出血框上的底色在离左裁切边21.6 mm处就停了。设置span: 'page'后,标题作为页面色带排版,不会被截断,底色可以伸到两边。两个框线画出中国印本书常见的文武双线,粗1.6 pt、细0.5 pt,相距2 mm。

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

script.js · 第317–322行在完整代码中
const voice = (styles) => (markdown.match(
  new RegExp(`:::paragraphs\\{style="(?:${styles})"\\}[\\s\\S]*?:::`, 'g')) ?? []).join('');
const kaiText = voice('headnote|note');
// Hei: headings and their attributes, seals, colophon, the cover's lines, folios 一 to 十.
const heiText = (markdown.match(/^#.*$/gm) ?? []).join('') + voice('seal|colophon')
  + '臨時大總統宣言書1912年1月1日中華民國臨時約法1912年3月11日一二三四五六七八九十';

Fontsource把这些字体的每个字重拆成约一百个文件,每个文件覆盖一段字符范围,loadCjkFonts只加载文本用到的那些文件。只交给它标题、钤印说明、版权说明、封面文字和页码时,Noto Sans TC每个字重加载10个文件;交给它整个样本,则要加载35个,而这里有三个字重。LXGW WenKai TC拿到题解和注释,加载16个文件。某种字体拿到的文本太少,截图就会失败(C12),并列出它不得不从后备字体借用的字符。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 081 · Dates and acronyms upright in vertical text ═══════
// https://postext.dev/en/cookbook/chinese-dates-upright
// Code: MIT · Text: 1912 documents, zh.wikisource (CC BY-SA 4.0); notes (CC BY 4.0)
// Fonts: Noto Serif TC, Noto Sans TC, LXGW WenKai TC (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// Two founding documents of the Republic of China, 1912, set vertically as a reader.
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 = 'chinese-dates-upright';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink, the vermilion of a seal, and the paper of a gazette
const palette = {
  ink: '#1e1a17', // text: a warm near-black
  seal: '#b1291f', // the one accent: the bands, the seal notes, the chapter heads
  tint: '#f6dccf', // the cover's double rule, a pale vermilion
  muted: '#6d645b', // fore-edge heads, the colophon
  paper: '#fffdf8',
};
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: 'seal (defaults)', value: { hex: palette.seal, model: 'hex' } },
];
// #endregion

const SONG = 'Noto Serif TC'; // 宋/明: the documents
const HEI = 'Noto Sans TC'; // 黑: titles, heads, labels
const KAI = 'LXGW WenKai TC'; // 楷: the editor's headnotes and notes
const BODY = 12; // pt, 小四
const LEAD = 21; // pt: a line gap of 0.75 em
const CHARS = 44; // characters to a line
const LINE = (CHARS * BODY * 25.4) / 72; // mm: the length of a line, 186.3
const TRIM = { w: 184, h: 260 }; // mm, 16开
const MARGIN = { top: 30, bottom: 22, side: 20 }; // mm, minimums: 天头 deeper than 地脚

// #region answer: vertical text where numbers of one or two digits stand upright
const layout = { layoutType: 'single', writingMode: 'vertical-rl' }; // binding 'auto': right
const cjk = {
  // 10月10日: each number of up to two digits stands upright in one cell (tate-chu-yoko);
  // 1912 and Sun Yat-sen stay on their side, as clreq sets long numbers and Latin words.
  uprightDigits: 2,
  // The type area in characters: 44 down each line, 19 lines to the page.
  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: 19 },
};

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

变化

#三位数也直立

设为3时,注释中的268和115不加标记就占一格,999以内的条号或页码也都如此;1912仍然横躺。

-  uprightDigits: 2,
+  uprightDigits: 3,

#所有数字都横躺

设为0时,没有数字会自动直立:10月10日像1912一样横躺,只有加了标记的268、115和ROC仍然直立。

-  uprightDigits: 2,
+  uprightDigits: 0,

常见问题

易错点

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

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

易错点

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

易错点

右装订的书用showBook显示跨页

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

  • Fontsource提供的Noto Serif TC没有爲和敎:它的样式表列出了这两个字,但没有哪个文件包含它们的字形。1912年印本的约法正是把為和教写成这两种字形。Canvas用系统字体画出了敎,PDF里则没有它的字形,截图报告了这个问题(C25)。读本改用為和教,同时把靑和决改为青和決,并在题解中作了说明。
  • Fontsource提供的LXGW WenKai TC把即、為、青、教画成旧字形卽、爲、靑、敎,放在宋体正文里同样的字旁边显得别扭。注释的措辞避开了这四个字;只有列举约法旧字形的那段题解需要它们。请以实际大小读一遍你自己注释中的楷体文字。
  • 横躺的数字与旁边的汉字之间像拉丁词一样留空,两侧各四分之一个全角(cjk.latinSpacing),所以题解读作1912 年;在一格内直立的数字则像汉字一样不留空。

致谢

文本
字体
Noto Serif TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1)
沙盒PDF