跳到主要内容
食谱编号77

排版食谱 · 第2章 · 字体与文字

专名号与书名号,竖排与横排

用:name和:book标记《项羽本纪》,先排成右翻的竖排页,再排成横排页:竖排时线在专名左侧,横排时在专名下方。

本页内容
类型
教科书
输出
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页,共3页

  • 英文样例:尚无中文版本
  • 成品尺寸140 × 203 mm
  • 1栏
  • Noto Serif TC 10.5/18
  • LXGW WenKai TC
  • Noto Sans TC
  • 3页
  • 难度
  • Postext 1.65.0
  • 排版用时76 ms
  • 168行代码

简单来说

《史记》读本的几页样张。示例演示怎样用朱红色给人名、地名画直线,给书名画波浪线,竖排和横排各排一遍。

成品一览

为一本《史记》读本排的三张样张,采用中文大32开图书140 × 203 mm的成品尺寸。正文是《项羽本纪》的开头,用古籍整理本的全式标点:每个人名、地名、国名和朝代名旁加一条直线,每个书名和篇名旁加一条波浪线,都用朱红色。第1页用楷体排题解和编者凡例。第2、3页把同一份Markdown排了两次,一次竖排,一次横排,于是这个跨页能看出标记的位置:竖排时在专名左侧,横排时在专名下方。这本书右侧装订,每个标题都印在一条靛蓝色色带上。Nº 044,1645年文本的《Lycidas》用欧洲的方式区分专名,即排成斜体。

这道食谱解答

  • 怎样在中文正文里用直线和波浪线标出专名和书名?
  • 为什么我的中文强调印出来是倾斜的字体,应该改用什么?
  • 怎样把中文书排成竖排、右侧装订?

简短回答

script.js · 第45–62行在完整代码中
// :name[項梁] draws the proper-name line, :book[史記] the book-title mark, :dots[…] dots.
const cjk = {
  bookTitleMark: 'wavy', // zh-Hant's default; mainland editions of the classics use it too
  annotationColor: col('mark'), // unset, the marks print in the colour of the text
  grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
};
// The book runs down the page, bound on the right: the lines stand left of the names.
const layout = { layoutType: 'single', writingMode: 'vertical-rl' };
// # 項羽本紀 {style="across"} sets the same Markdown across the page, 28 characters to
// the line: the lines run under the names. Its margins set its grid; the book's grid
// counts down the page.
const MEASURE = 28 * SIZE * PT; // mm
const across = {
  id: 'across',
  layout: { layoutType: 'single', writingMode: 'horizontal-tb' },
  margins: { top: mm(SIDE), bottom: mm(H - SIDE - 25 * LEAD * PT), // 25 lines
    left: mm((W - MEASURE) / 2), right: mm((W - MEASURE) / 2) },
};

用料

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

做法

#1 · 标记由标记语法给出,位置由书写方向决定

代码见上文的简短回答。:name[項梁]和:book[史記]把字符保留在正文中,所以搜索、复制出的文字和PDF读到的都是項梁和史記,同时在字旁加上标记(中文标记、注音和割注)。标记排在哪一侧只取决于书写方向:layout.writingMode: 'vertical-rl'把线放在字的左侧,而版式为'horizontal-tb'的标题样式across把线放在字的下方。bookTitleMark: 'wavy'本是zh-Hant文档的默认值;这里明确写出来,是因为一旦改成zh-Hans,书名就会印成《》。同类标记首尾相接时,比如東漢班固或史記項羽本紀,两条线在相接的一端各让出八分之一em,这样读起来是两个专名。

#2 · 为标记留出空间的行距

script.js · 第32–41行在完整代码中
const [SONG, HEI, KAI] = ['Noto Serif TC', 'Noto Sans TC', 'LXGW WenKai TC']; // 宋, 黑, 楷
const PT = 25.4 / 72; // mm in a point
const [W, H] = [140, 203]; // mm: 大32開
const SIZE = 10.5; // pt: 五號
// A gap of 7.5 pt (0.71 em) between lines: a line of marks needs half an em of it, dots on
// one side and lines on the other five eighths. At 15 pt the build reports every marked
// paragraph (cjkMarksExceedLeading: gap 0.43 em).
const LEAD = 18; // pt
const [CHARS, LINES] = [42, 17]; // the vertical grid: characters down a line, lines across
const SIDE = (W - LINES * LEAD * PT) / 2; // mm: the side margins of a vertical page

标记位于行与行之间的空隙中,从不改变行距(标记、注音和割注)。10.5 pt字号配18 pt行距,空隙是0.71 em,足以容纳一行的专名线和下一行的着重点,如第1页第五条凡例所示。网格以字数计算页面:每行42字,共17行;它会调整页边距,使版心正好是这个大小:天头25.7 mm,地脚21.7 mm(字符网格)。

#3 · 一个章首页设计,随页面转向

script.js · 第66–89行在完整代码中
// The grid centres the text between the minimum margins; the band stops at its foot.
const FOOT = 20 + (H - 24 - 20 - CHARS * SIZE * PT) / 2; // mm, with minimums of 24 and 20
const BAND = SIDE + 3.5 * LEAD * PT; // mm from the trim, which is the right edge down the page
const onBand = { align: 'left', overflow: 'wrap' }; // design text centres and cuts by default
const next = (id, y) => ({ anchor: { to: `#${id}`, edge: 'below' }, offset: { y: mm(y) } });
const opener = {
  enabled: true,
  minHeight: pt(4 * LEAD), // the text starts on the fifth line, half a line clear of the band
  slot: { elements: [
    // Across the page the band's length runs past the trim; down it, it ends at the text's
    // foot, clear of the folio.
    { kind: 'box', id: 'band', style: { backgroundColor: col('band') },
      placement: { anchor: { to: 'bleed', edge: 'top-left' },
        size: { width: mm(H - FOOT), height: mm(BAND) } } },
    { kind: 'text', id: 'kicker', content: '{attr.kicker}', ...onBand, fontFamily: HEI,
      fontWeight: 700, fontSize: pt(8), letterSpacing: pt(1.6), color: col('tint'),
      placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(6 - SIDE) } } },
    { kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: SONG,
      fontWeight: 700, fontSize: pt(46), lineHeight: 1, letterSpacing: pt(3),
      color: col('paper'), placement: next('kicker', 2) },
    { kind: 'text', id: 'byline', content: '{attr.byline}', ...onBand, fontFamily: KAI,
      fontSize: pt(10), color: col('tint'), placement: next('title', 2) },
  ] },
};

标题设计在所在页面的文本流中排版,所以同一组元素可以用于两个方向(竖排)。色带锚定在出血框的左上角,在横排页上横贯页首,在竖排页上则沿右边缘竖下,那里正是阅读的起点。眉题、标题和署名也在文本流中堆叠:横排时上下相接,竖排时左右相接。色带的长度沿文本流方向度量:181.3 mm让它在竖排正文的底端停下,避开页码,而在横排页上则伸过成品线。

#4 · 右侧装订书的页码

script.js · 第93–102行在完整代码中
const foot = (id, content, parity, edge, x, extra) => ({ kind: 'text', id, content, parity,
  fontFamily: HEI, fontSize: pt(7), color: col('muted'), ...extra,
  placement: { anchor: { to: 'page', edge }, offset: { x: mm(x), y: mm(-11) } } });
const folio = { fontFamily: SONG, fontSize: pt(9) };
// Bound on the right, a recto (odd) lies left of the spine: its outer edge is its left one.
const footer = { elements: [
  foot('folio-odd', '{pageNumber}', 'odd', 'bottom-left', SIDE, folio),
  foot('folio-even', '{pageNumber}', 'even', 'bottom-right', -SIDE, folio),
  foot('slug', '{attr.slug}', 'all', 'bottom', 0, { letterSpacing: pt(0.4) }),
] };

竖排文字让书在右侧装订(装订):第1页位于书脊左侧,右页(奇数页)的外侧边是它的左边。奇数页码放在左下,偶数页码放在右下,与西文书相反;pageNumbering.format: 'trad-chinese-informal'把页码印成一、二、三。两者之间的书眉文字来自每个标题的属性slug="…";它和版权说明是英文版与西班牙文版之间仅有的不同之处。

#5 · 第二种油墨

script.js · 第17–29行在完整代码中
const palette = {
  ink: '#221e1b', // the text
  band: '#23394b', // the opener band and the small heads
  mark: '#b5412c', // the name, title and emphasis marks: the second ink
  tint: '#c7d2da', // kickers and bylines on the band
  muted: '#6f6a64', // folios, slug lines, the colophon
  paper: '#ffffff',
};
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: 'band (defaults)', value: { hex: palette.band, model: 'hex' } },
];

古籍整理本用正文的墨色印标记。给学生用的读本可以把标记印成第二种颜色,使它们与字的笔画分开:annotationColor把标记关联到调色板中的mark,即朱批的朱红色;改动这一项,全书每一条线、每一个点都会随之变色。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 077 · Proper-name and book-title marks, across and down ═════
// https://postext.dev/en/cookbook/proper-name-marks
// Code: MIT · Text: Sima Qian, Shiji 7 (PD) · Punctuation, headnote, conventions: CC BY 4.0
// Fonts: Noto Serif TC, Noto Sans TC, LXGW WenKai TC (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// Specimen pages for a classical reader: the opening of the Basic Annals of Xiang Yu with
// its proper-name lines and wavy title lines, set down the page and then across it.
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 slug lines and the colophon ('en' | 'es')
const RECIPE = 'proper-name-marks';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: the indigo of a thread-bound cover, vermilion for the marks
const palette = {
  ink: '#221e1b', // the text
  band: '#23394b', // the opener band and the small heads
  mark: '#b5412c', // the name, title and emphasis marks: the second ink
  tint: '#c7d2da', // kickers and bylines on the band
  muted: '#6f6a64', // folios, slug lines, the colophon
  paper: '#ffffff',
};
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: 'band (defaults)', value: { hex: palette.band, model: 'hex' } },
];
// #endregion
// #region type: 五號 on 18 pt, 42 characters by 17 lines down the page
const [SONG, HEI, KAI] = ['Noto Serif TC', 'Noto Sans TC', 'LXGW WenKai TC']; // 宋, 黑, 楷
const PT = 25.4 / 72; // mm in a point
const [W, H] = [140, 203]; // mm: 大32開
const SIZE = 10.5; // pt: 五號
// A gap of 7.5 pt (0.71 em) between lines: a line of marks needs half an em of it, dots on
// one side and lines on the other five eighths. At 15 pt the build reports every marked
// paragraph (cjkMarksExceedLeading: gap 0.43 em).
const LEAD = 18; // pt
const [CHARS, LINES] = [42, 17]; // the vertical grid: characters down a line, lines across
const SIDE = (W - LINES * LEAD * PT) / 2; // mm: the side margins of a vertical page
// #endregion

// #region answer: marks by the markup, their side by the writing mode
// :name[項梁] draws the proper-name line, :book[史記] the book-title mark, :dots[…] dots.
const cjk = {
  bookTitleMark: 'wavy', // zh-Hant's default; mainland editions of the classics use it too
  annotationColor: col('mark'), // unset, the marks print in the colour of the text

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

变化

#书名印成《》

古籍之外,大陆图书用书名号括住书名:Markdown保持不变,书名号作为正文标点印出。

-  bookTitleMark: 'wavy', // zh-Hant的默认值;大陆的古籍整理本也用它
+  bookTitleMark: 'brackets', // 《史記》《項羽本紀》

#标记用正文墨色印

不设annotationColor,每个标记就取它所标注的块的颜色。

-  annotationColor: col('mark'), // 不设时,标记印成正文的颜色

常见问题

易错点

用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]。 右翻书 →

易错点

中文没有斜体

CJK字体家族不带斜体,中文排版用字旁的着重号标示强调,而不是倾斜。在标记为中文的文档中,*…*给其中的汉字加着重号,拉丁文词仍用斜体(cjk.emphasis: 'dots',中文的默认值);:dots[…]可以在任何地方加着重号。设置cjk.emphasis: 'italic'时,或在标记为en或es的文档中,*…*会让Canvas把正体字形倾斜,这种合成的伪斜体是中文排版从来不用的(PDF会退回正体字型):保留中文标记,或者通过段落样式或标签样式,用粗体或楷体(LXGW WenKai)表示强调。 中日韩字体 →

版面警告 · cjkMarksExceedLeading

着重号等挤到相邻的行

原因. 带着重号或专名号、书名号的段落,行间空隙不到半个em(两侧都有标记时不到八分之五em):这些标记位于行距之中,而行距不会为它们增高,于是碰到下一行。

解决. 给该段落设一个行距更大的段落样式,或调大`bodyText.lineHeight`。 文档 →

  • 由版面设计绘制的标题通过设计印出标题文字,而设计中的文字会丢掉标记:# :book[項羽本紀]在色带上不会显示波浪线。书眉、题注和表格单元格印出的文字也不带标记。
  • Postext不会因cjkMarksExceedLeading而停止:构建会把它列入doc.contentWarnings,沙盒的检查面板也会显示,但页面照样印出,标记挤到下一行上。改动行距后,请查看这个列表;在15 pt行距下,这几页中每个带标记的段落都在列表里。

致谢

文本
  • The opening of the Basic Annals of Xiang Yu (項羽本紀), Records of the Grand Historian (史記), chapter 7; characters from the zh.wikisource transcription · Sima Qian (司馬遷) · 公有领域
  • The punctuation, the paragraphs and the marks of the passage, the headnote (題解), the conventions (凡例), the slug lines and the colophon · Ignacio Ferro · CC BY 4.0
字体
Noto Serif TC (SIL OFL 1.1) · Noto Sans TC (SIL OFL 1.1) · LXGW WenKai TC (SIL OFL 1.1)
沙盒PDF