跳到主要内容
食谱编号119

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

竖排的俳句与短歌

芭蕉游记中的俳句和啄木的十一首三行短歌排在四六判页面上:一句一行,从行头缩进,署名靠近行底。

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

页码二–三 · 第2–3页,共8页

  • 英文样例:尚无中文版本
  • 成品尺寸127 × 188 mm
  • 1栏
  • Shippori Mincho 10/19
  • Noto Sans JP
  • 8页
  • 难度
  • Postext 1.65.0
  • 排版用时91 ms
  • 155行代码

简单来说

一本小小的日文诗集:芭蕉的游记,俳句各占一行;还有啄木的短诗,每首三行,翻页时不会被拆开。

成品一览

一本小诗集的八页,127 × 188 mm的四六判页面,右侧装订。第一部分是芭蕉《奥之细道》(おくのほそ道)中的七站,散文连同其中的俳句;第二部分是石川啄木《一握之砂》(一握の砂)中的十一首短歌,每首都按他写下时的三行排。散文从上到下排,每行36字,用10 pt的Shippori Mincho,行距宽松,为1.9 em。每首俳句单独占一行,低三字,每首短歌低两字,曾良的那首俳句在行的下部署名曾良。短歌从不跨页拆开,各组之间用一个柿色的*隔开。欧洲的诗集见Nº 015;竖排的中文唐诗见Nº 083。

这道食谱解答

  • 怎样排诗歌:每句一行,诗节间留空,折行悬挂缩进,不断词?
  • 哪些字体能排日文,并在屏幕和PDF中让汉字采用日文字形?

简短回答

script.js · 第33–48行在完整代码中
// A haiku is a paragraph of one line, so a style sets where it starts: three characters down
// from the head of the line. Takuboku's tanka keep his three lines in a :::verse block, two
// down; 曾良 signs his haiku raised five characters from the foot (地から五字上げ).
const paragraphStyles = [
  { id: 'haiku', indent: em(3), firstLineIndent: em(0), marginTop: pt(0), marginBottom: pt(0) },
  // A poem's style gives its indent and the space under the poem: one blank line.
  { id: 'tanka', indent: em(2), marginTop: pt(0), marginBottom: pt(LEAD) },
  { id: 'by', textAlign: 'end', endIndent: em(5), firstLineIndent: em(0) },
  // The ornament between groups of poems, in the middle of its line, with a blank line after
  // it to match the one the group before it leaves.
  { id: 'ornament', textAlign: 'center', firstLineIndent: em(0), color: col('persimmon'),
    marginBottom: pt(LEAD) },
];
//   :::paragraphs{style="haiku"}       :::paragraphs{style="by"}
//   夏草や兵どもが夢の跡                   曾良
//   :::                                :::

用料

类型
Shippori Mincho, Noto Sans JP(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 一行诗是一个段落,样式决定它从哪里开始

代码见上文的简短回答。一首俳句只有一行,所以它是:::paragraphs围栏里的一个独立段落,由围栏的样式设定缩进:indent: em(3)让俳句从行头往下空三字(青空文库的文本低两字,低三字让诗周围更疏朗),firstLineIndent: em(0)让正文的一字缩进不再叠加上去。一首俳句大约17个字,放进任何一行36字的行里都不会折行。署名是一个单独的段落:textAlign: 'end'把它靠到行底(地付き,jitsuki),endIndent: em(5)再从那里往上提五字(地から五字上げ),与本文所据的版本一致(段落样式)。

#2 · 每首短歌排在同一页

script.js · 第52–63行在完整代码中
// The tanka of a group are one :::verse block, each a stanza of three lines with a blank
// line between: a line of verse a line of Markdown, one blank line of the grid between two
// tanka. keepStanzas=3 keeps a stanza of three lines whole, so a tanka is never cut at the
// foot of a page: it moves on to the next.
//   :::verse{style="tanka" keepStanzas=3}
//   東海の小島の磯の白砂に
//   われ泣きぬれて
//   蟹とたはむる
//
//   頬につたふ
//   …
//   :::

啄木的短歌是一个:::verse块,每首短歌是一个诗节:它的三行就是Markdown的三行,源文本中两首短歌之间的空行在诗与诗之间留出基线网格的一个空行。诗的样式给出两字缩进和组后的一行,诗行像任何一列一样从天头垂下。keepStanzas=3让每个三行的诗节保持完整:第5页上,第三首短歌在部分标题和前两首之下放不下,于是整首移到第6页开头,而不是把第一行留在前一页。两组之间的装饰引出下一组,所以它随该组的第一首短歌一起移走,而不会孤零零地留在页脚(:::verse)。

#3 · 把地名撑到同一宽度

script.js · 第67–72行在完整代码中
// The place names over the prose take two lines (2行取り), four characters down, and a
// two-character name is spaced out to three (字取り: 平泉 → 平 泉), so they all end level.
const place = {
  level: 2, fontFamily: MINCHO, fontWeight: 700, fontSize: pt(11),
  lineSpan: 2, indent: em(4), jidori: 3,
};

芭蕉旅途中的各站是二级标题,高两个正文行(2行取り),所以后面的散文和俳句仍在网格上。jidori: 3把较短的地名撑开到它自己的三个字宽(字取り):平泉印成平 泉,中间空一整字,每个地名都与立石寺、最上川在同一高度结束。本来就是三个字的地名不做改动(按级别覆盖)。

#4 · 每一部分另起一页

script.js · 第76–97行在完整代码中
// A design on a vertical page is laid out in the flow frame: x runs down the column from
// the head of the type area, y across the page leftwards from its right edge.
const at = (down, across) => ({ anchor: { to: 'container', edge: 'top-left' },
  offset: { x: pt(down), y: pt(across) } });
const TITLE = 18; // pt
const part = {
  level: 1, breakBefore: { enabled: true, parity: 'any' }, // the next page, either side
  advancedDesign: { enabled: true, minHeight: lines(5), slot: { elements: [
    { kind: 'text', id: 'title', content: '{titleText}', fontFamily: MINCHO, fontWeight: 700,
      fontSize: pt(TITLE), lineHeight: 1, letterSpacing: pt(4), color: col('ink'),
      placement: at(3 * BODY, 1.5 * LEAD - TITLE / 2) },
    { kind: 'text', id: 'abridged', content: '(抄)', fontFamily: MINCHO, fontSize: pt(9),
      color: col('ink'), placement: { anchor: { to: '#title', edge: 'right-of' },
        offset: { x: pt(6), y: pt((TITLE - 9) / 2) } } },
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.6),
      color: col('persimmon'), placement: { ...at(3 * BODY, 2.5 * LEAD),
        size: { width: pt(4 * TITLE) } } },
    { kind: 'text', id: 'poet', content: '{attr.author}', fontFamily: MINCHO, fontSize: pt(11),
      letterSpacing: pt(3), color: col('ink'),
      placement: at(CHARS * BODY - 4 * 11 - 3 * 3 - 2 * BODY, 3.5 * LEAD - 11 / 2) },
  ] } },
};

每一部分是一个一级标题,它的设计排出标题,在标题之后用anchor.to: '#title'紧接着放一个小号的(抄),意思是“选录”,标题旁一条柿色短线,诗人的名字靠近行底。设计预留五行,正文在这五行之后、在同一套网格上开始。

#5 · 选一款有旧式符号的字体

script.js · 第279–285行在完整代码中
const title = markdown.match(/^title: "(.*)"$/m)[1];
const heads = markdown.match(/^#+ [^{\n]*/gm).join('');
await loadFonts(FONTS, markdown); // the Latin files: the colophon
await loadCjkFonts({ [MINCHO]: ['400'] }, markdown, { vertical: true });
await loadCjkFonts({ [MINCHO]: ['700'] }, heads);
await loadCjkFonts({ [GOTHIC]: ['400'] },
  `${title}${heads}${markdown.match(/colophon="([^"]*)"/)[1]}一二三四五六七八九十`, { vertical: true });

芭蕉的散文用旧式叠字符〻写重复的字(日〻、人〻),更早的文本还用竖长的くの字点〳〵。Zen Old Mincho两个都没有:Canvas会从系统字体借用,PDF会画出空框。Shippori Mincho、Noto Serif JP和Shippori Mincho B1两个都有,所以诗歌用Shippori Mincho排(中文、日文和韩文字体)。青空文库的文本还保留了编者对旧假名用法的注记とら{え|(へ)}て,在芭蕉写的假名旁印出通行的写法。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 119 · Haiku and tanka set vertically ═══════════════════
// https://postext.dev/en/cookbook/haiku-and-tanka
// Code: MIT · Text: 芭蕉『おくのほそ道』, 啄木『一握の砂』, Aozora Bunko (PD) · Pictures: none
// Fonts: Shippori Mincho, 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 poems are Japanese in both
const RECIPE = 'haiku-and-tanka';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink, one persimmon, a soft poetry stock
const palette = {
  ink: '#22201d', // the poems
  persimmon: '#b5512c', // 柿: the part titles' rule and the ornaments
  muted: '#6a645c', // the hashira, the folios, the colophon
  paper: '#fbf8f1',
};
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.persimmon, model: 'hex' } },
];
// #endregion
// Shippori Mincho: it has the 〻 of 日〻 and 人〻, which Zen Old Mincho lacks.
const [MINCHO, GOTHIC] = ['Shippori Mincho', 'Noto Sans JP'];
const [BODY, LEAD, CHARS, LINES] = [10, 19, 36, 14]; // pt, pt: 36字 × 14行, a 1.9 em pitch
const lines = (n) => pt(n * LEAD);

// #region answer: a haiku on one line three characters down, a tanka in three, 地付き names
// A haiku is a paragraph of one line, so a style sets where it starts: three characters down
// from the head of the line. Takuboku's tanka keep his three lines in a :::verse block, two
// down; 曾良 signs his haiku raised five characters from the foot (地から五字上げ).
const paragraphStyles = [
  { id: 'haiku', indent: em(3), firstLineIndent: em(0), marginTop: pt(0), marginBottom: pt(0) },
  // A poem's style gives its indent and the space under the poem: one blank line.
  { id: 'tanka', indent: em(2), marginTop: pt(0), marginBottom: pt(LEAD) },
  { id: 'by', textAlign: 'end', endIndent: em(5), firstLineIndent: em(0) },
  // The ornament between groups of poems, in the middle of its line, with a blank line after
  // it to match the one the group before it leaves.
  { id: 'ornament', textAlign: 'center', firstLineIndent: em(0), color: col('persimmon'),
    marginBottom: pt(LEAD) },
];
//   :::paragraphs{style="haiku"}       :::paragraphs{style="by"}
//   夏草や兵どもが夢の跡                   曾良
//   :::                                :::

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

变化

#在俳句的三个短语之间空格

学校的选本有时在5、7、5三段之间加一个全角空格,方便初学这一诗体的读者;这个空格是正文里的一个字符。

-{夏草|なつくさ}や{兵|つはもの}どもが夢の跡
+{夏草|なつくさ}や {兵|つはもの}どもが 夢の跡

#允许长的短歌拆开

不设keepStanzas时,一首短歌可以从一页的底部开始,按段末孤行和段首孤行规则在下一页接着排,收录上千首诗的厚选本会这样做。

-:::verse{style="tanka" keepStanzas=3}
+:::verse{style="tanka"}

常见问题

易错点

日文文本标记为'ja',不要用zh-Hans或LANG

食谱的版本是en和es,但日文示例在两个版本里都是日文:`locale: LANG`会把它标记为英文或西班牙文,中文标记则会按中文规则排它(开明式标点、小假名可以出现在行首、图代替図、PDF中用中文字形)。postext 1.30起,这个标记也是文字成形所用的语言(测量、绘制和嵌入都按它进行),所以'ja'以外的标记给出的不是日文字形(中文标记给出中文字形),断行的位置也不同。写'ja':它选用日本地区(JLReq断行和标点、芝麻着重号、振假名的分布、図和表标签),并关闭断词。lint会让带假名却标记为zh或ko的文本失败。 日文禁则处理 →

易错点

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

易错点

Fontsource的字符范围可能包含文件里没有的字

Fontsource给每个文件标出unicode-range,loadCjkFonts按示例文字加载范围覆盖它们的文件,但范围可能比文件实际收录的字多。Zen Old Mincho负责U+3028–303F的切片没有〻,也没有长重复符号〳〴〵,这款字体也没有带长音符号的ō、ū、ā;Shippori Mincho B1的latin-ext文件只有寥寥几个字符,ō、ū、ā都不在其中。pen运行时不会报错:屏幕上这些字符来自系统字体并按它测量,PDF印出该字体的.notdef方框,只有事后的C25检查才会报告。选定字体之前,先在字体里查一查生僻符号或罗马字词(用fontTools检查Fontsource的文件),再用收有这些字的字体来排:Shippori Mincho B1和Noto Serif JP有〻和〳〴〵,Noto Serif JP和Noto Sans JP有带长音符号的元音。 中日韩字体 →

致谢

文本
字体
Shippori Mincho (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1)
沙盒PDF