简单来说
一份日本町内会的通讯,从上到下竖排。示例展示日文书写数字的几种方式,以及日期在竖排中怎样保持易读。
成品一览
一份町内会报《東若葉台だより》第百二十号,竖排四页,B5,右侧装订:夏季祭典的通知、八月日历、会费说明和一张捐款收据,以及町会的简史。町会是虚构的,但其中的数字都按日本编辑的习惯书写。期号、祭典的第三十二回和到场的二千四百人用十、百、千计数;年份逐位书写,如二〇二六年、一九六〇年;收据金额用大写数字(大字)壱萬弐阡,无法添笔改动;时间和日期用阿拉伯数字,22在一格内直立。列表依次为一、→(一)→イ→あ,日历排在封底。
这道食谱解答
- 怎样用汉字数字把章编号为第一章,或把列表项编为あいう和イロハ?
- 为什么我的日文按中文规则排了:标签是图、小假名出现在行首、汉字是中文字形?
简短回答
// formatNumeral is the counter the engine numbers pages, lists and headings with.
const ISSUE = 120;
const kan = (n) => formatNumeral(n, 'japanese-informal'); // 120 → 百二十: counted
const pos = (n) => formatNumeral(n, 'cjk-decimal'); // 2026 → 二〇二六: digit by digit
const daiji = (n) => formatNumeral(n, 'japanese-formal'); // 12000 → 壱萬弐阡: on money
// {{daiji:12000}} in the text: the amount of a receipt in the hard-to-alter daiji.
const withDaiji = (md) => md.replace(/\{\{daiji:(\d+)\}\}/g, (_, n) => daiji(Number(n)));
const cjk = {
grid: { enabled: true, charsPerLine: CHARS, linesPerPage: LINES },
uprightDigits: 2, // 8月22日: one or two Arabic digits stand in one cell (the default)
};
// Sections 一、二、三、, items (一)(二), then イ ロ ハ and あ い う beneath them.
const sectionLevel = { level: 2, numberingTemplate: '{2:一}、', numberSeparator: '',
fontFamily: GOTHIC, fontWeight: 700, fontSize: pt(12), color: col('leaf'), lineSpan: 2 }; // 二行取り
const level = (n, numberFormat, prefix, separator) => ({ level: n, numberFormat, prefix,
separator }); // each level starts where the text of the one above starts
const orderedLists = {
fontFamily: GOTHIC, color: col('leaf'), fontWeight: 700, gap: em(0.5),
marginTop: pt(0), marginBottom: pt(0), itemSpacing: pt(0),
levels: [level(1, 'japanese-informal', '(', ')'), level(2, 'katakana-iroha', '', ''),
level(3, 'hiragana', '', '、')],
};
用料
做法
#1 · 按数字所处的位置选择写法
代码见上文的简短回答。formatNumeral就是引擎为页码、列表和标题编号所用的计数器,示例在自己组合的数字上调用它:japanese-informal计数(120 → 百二十,十、百、千前不加一),cjk-decimal逐位书写(2026 → 二〇二六),japanese-formal给出金额的大写(12000 → 壱萬弐阡)。正文里的{{daiji:12000}}会变成收据金额,数字只需用阿拉伯数字输入一次。同样的风格也用于序号:各节是{2:一}、,orderedLists.levels依次设为(一)、katakana-iroha(イロハ)和带“、”的hiragana(あ、い、う)。cjk.uprightDigits: 2让8月22日和23日不加标记就直立;「雨が降ったら中止!?」中的!?共用一格,这是日文的默认行为(竖排中的数字)。

#2 · 报头做成右边缘的色带
const BAND = 46; // mm from the right trim edge
const at = (x, y, extra = {}) => ({ anchor: { to: 'page', edge: 'top-left' },
offset: { x: mm(x), y: mm(y) }, ...extra }); // x down the sheet, y leftward from its right
const onBand = { color: col('paper'), overflow: 'wrap', align: 'left' };
// The date of issue, composed from kan() and pos() as the issue number is: design text the
// contentInConfig check allows, since spelling it is what the recipe shows (#849).
const ISSUED = `${pos(2026)}年(令和${kan(8)}年)${kan(8)}月${kan(1)}日発行`;
const masthead = {
id: 'masthead', numbered: false, toc: false, runningChapter: false,
breakBefore: { enabled: true, parity: 'any' },
advancedDesign: { enabled: true, minHeight: mm(BAND - 15), slot: { elements: [
{ kind: 'box', id: 'band', style: { backgroundColor: col('leaf') },
placement: { anchor: { to: 'bleed', edge: 'top-left' }, size: { height: mm(BAND) } } },
{ kind: 'text', id: 'title', content: '{titleText}', ...onBand, fontFamily: ROUND,
fontWeight: 700, fontSize: pt(36), lineHeight: 1.1, letterSpacing: pt(3),
placement: at(HEAD, 9) },
{ kind: 'text', id: 'issue', content: `第${kan(ISSUE)}号`, ...onBand, fontFamily: GOTHIC,
fontWeight: 700, fontSize: pt(12), letterSpacing: pt(2), placement: at(HEAD, 26) },
{ kind: 'text', id: 'date', content: ISSUED,
...onBand, fontFamily: GOTHIC, fontSize: pt(10), align: 'right',
placement: at(HEAD, 26, { size: { width: mm(LINE) } }) },
{ kind: 'text', id: 'publisher', content: '{author}', ...onBand, fontFamily: GOTHIC,
fontSize: pt(10), align: 'right', placement: at(HEAD, 33, { size: { width: mm(LINE) } }) },
{ kind: 'text', id: 'latin', content: '{attr.latin}', ...onBand, fontFamily: GOTHIC,
fontSize: pt(7.5), placement: at(HEAD, 40) },
] } },
};
在竖排页面上,文字流的“顶端”是纸张的右边缘,所以锚定在出血框顶端的标题设计就是沿这条边的色带,它的size.height就是它在纸上的宽度。期号和日期是用kan()和pos()拼出的设计文字,日期以align: 'right'止于版心底端。
#3 · 日历单独占一页
const DAYS = { 2: '訓練', 9: '清掃', 13: 'お盆', 18: '練習会', 19: '練習会',
22: '夏祭り', 23: '夏祭り', 30: '役員会' };
const day = (d) => (d ? { content: `**${d}**\n${DAYS[d] ?? '\u00a0'}`, align: 'center',
...(DAYS[d] ? { background: col(d === 22 || d === 23 ? 'blush' : 'tint') } : {}) }
: { content: '' });
const weeks = []; // 1 August 2026 is a Saturday
for (let d = -5; d <= 31; d += 7) weeks.push([0, 1, 2, 3, 4, 5, 6].map((k) => day(d + k > 0
&& d + k <= 31 ? d + k : 0)));
const calendar = { id: 'calendar', typeId: 'table', kind: 'table', createdAt: 0, updatedAt: 0,
// An upright table takes every line of the vertical page it stands on (gap:
// vertical-tables): the calendar is the back page, cited at the end of the text.
placement: { position: 'top', span: 'page' },
caption: '八月の行事。13日から16日まではごみの収集がありません。',
table: { model: { headerRowCount: 1, rows: [[...'日月火水木金土'].map((c) => ({ content: c,
isHeader: true, align: 'center' })), ...weeks] } } };
const resourceTypes = [{ id: 'table', name: '表', shortLabel: '表', captionPrefix: '表',
numberingTemplate: '{n}', counterFormat: '一', resetOn: 'never' }]; // 表一, 表二…
在竖排页面上,表格直立摆放、横向阅读,日文书一般这样印表;它会占用所在页的全部行。日历在最后一段之后作为整页浮动体引用,于是成为封底,前面的文字照常排满各页。resourceTypes用记号一给它编号(表一),ja文档默认把标签排成“表一 ”:标签与序号相连,后面跟一个全角空格。
#4 · 每种字体只加载它要排的文字
const heads = (markdown.match(/^#+ .*$/gm) ?? []).join('');
const gothicText = `${heads}${markdown}第号年月日発行令和${kan(ISSUE)}${pos(2026)}${
calendar.caption}日月火水木金土${Object.values(DAYS).join('')}領収証(記入例)表一`;
Noto Serif JP排正文;Noto Sans JP排标题、列表、日历和收据标签;Zen Maru Gothic只排报名。每种字体只加载它自己所需字符的Fontsource文件,再加上示例生成的数字。
完整食谱
// ═══ Postext Cookbook · Nº 129 · Kanji numerals, counters and dates in vertical text ═══
// https://postext.dev/en/cookbook/kanji-numerals-and-dates
// Code: MIT · Text: written for the recipe (CC BY 4.0)
// Fonts: Noto Serif JP, Noto Sans JP, Zen Maru Gothic (SIL OFL 1.1) · Needs postext ≥ 1.34.0
// A neighbourhood newsletter set vertically: every way Japanese writes a number.
import {
buildDocument, withLoadedFonts, renderPageToCanvas, loadVerticalAlternates, formatNumeral,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'en'; // @lang: the language of the frame; the newsletter is Japanese in both
const RECIPE = 'kanji-numerals-and-dates';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: ink, the green of young leaves, its tint, a festival red and its blush
const palette = {
ink: '#1f2420', // the text
leaf: '#2f6b3f', // masthead band, section numbers (6.4:1 on the paper)
tint: '#e4efdf', // the calendar's marked days, the receipt
red: '#b4362b', // the receipt's amount
blush: '#f4d4cc', // the festival days in the calendar
muted: '#5f665f', // folios, the colophon
paper: '#fdfdf9',
};
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: 'leaf (defaults)', value: { hex: palette.leaf, model: 'hex' } },
];
// #endregion
const MINCHO = 'Noto Serif JP'; // the text
const GOTHIC = 'Noto Sans JP'; // section heads, labels, the calendar
const ROUND = 'Zen Maru Gothic'; // the masthead's title
const [BODY, LEAD] = [11, 20]; // pt: large print for every age on the street
const [CHARS, LINES] = [44, 20];
const PT = 25.4 / 72; // mm in a point
const TRIM = { w: 182, h: 257 }; // mm, B5
const LINE = CHARS * BODY * PT; // mm: 170.7, the length of a line
const HEAD = 30 + (TRIM.h - 30 - 24 - LINE) / 2; // mm: the head of the type area
// #region answer: one number, four spellings, chosen by where it stands
// formatNumeral is the counter the engine numbers pages, lists and headings with.
const ISSUE = 120;
const kan = (n) => formatNumeral(n, 'japanese-informal'); // 120 → 百二十: counted
const pos = (n) => formatNumeral(n, 'cjk-decimal'); // 2026 → 二〇二六: digit by digit
const daiji = (n) => formatNumeral(n, 'japanese-formal'); // 12000 → 壱萬弐阡: on money
// {{daiji:12000}} in the text: the amount of a receipt in the hard-to-alter daiji.
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#年份一律计数书写
有人在正文中更喜欢二千二十六年而不是二〇二六年;改一下pos的风格即可。
-const pos = (n) => formatNumeral(n, 'cjk-decimal'); // 2026 → 二〇二六: digit by digit
+const pos = (n) => formatNumeral(n, 'japanese-informal'); // 2026 → 二千二十六#三位数字也直立
设为3后,正文中的100或365也各占一格。
- uprightDigits: 2, // 8月22日: one or two Arabic digits stand in one cell (the default)
+ uprightDigits: 3,常见问题
易错点
日文文本标记为'ja',不要用zh-Hans或LANG
食谱的版本是en和es,但日文示例在两个版本里都是日文:`locale: LANG`会把它标记为英文或西班牙文,中文标记则会按中文规则排它(开明式标点、小假名可以出现在行首、图代替図、PDF中用中文字形)。postext 1.30起,这个标记也是文字成形所用的语言(测量、绘制和嵌入都按它进行),所以'ja'以外的标记给出的不是日文字形(中文标记给出中文字形),断行的位置也不同。写'ja':它选用日本地区(JLReq断行和标点、芝麻着重号、振假名的分布、図和表标签),并关闭断词。lint会让带假名却标记为zh或ko的文本失败。 日文禁则处理 →
易错点
日文要用日文字体排
Noto Serif SC和TC里有假名,但汉字是中文字形(直、骨、角都不同),假名也是中文字体的设计。正文用Noto Serif JP或Shippori Mincho B1,标题用Noto Sans JP,用loadCjkFonts加载。Fontsource的日文文件里没有变体假名等历史假名(U+1B000–1B16F):loadCjkFonts遇到它们会失败,PDF里印出空框,所以要写现代假名,或者把含有这些字的字体放进食谱的assets。Shippori Mincho也没有带长音符号的ō和ū:罗马字要用拉丁字体排。 假名、汉字与罗马字 →
易错点
中文字体通过cjk块分片加载
Fontsource把一个中文、日文或韩文字体家族按每个字重约一百个文件提供,每个文件覆盖一段字符范围。loadFonts只获取latin文件,所以屏幕上的汉字来自系统字体,测量不准;fontsourceProvider交给PDF的也是这个latin文件,汉字印出来是空框。列出kit中的cjk块,在loadFonts之后调用loadCjkFonts(FONTS, markdown)(书中用到几种CJK字体时,每种字体调用一次,并传入它所排的文字),并给renderToPdf传fontProvider: cjkPdfProvider:两者都会取用包含文中字符的那些文件。 中日韩字体 →
- 日历单独占一页,是因为直立的表格会占用竖排页面的全部行(缺口:竖排中的表格)。表格若要与正文同页,需要横排页面,或改用由标题设计放置的SVG图。
- 同一个计数器在中文里写成一百二十、一千零一,在日文里写成百二十、千一。要写明
locale: 'ja',否则记号一会选用中文写法。中文读本竖排中的日期与缩略词直立用同样的uprightDigits排日期。
致谢
- 文本
- The newsletter of a fictional neighbourhood association, written in Japanese for this recipe · Postext Cookbook · CC BY 4.0
- 字体
- Noto Serif JP (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1) · Zen Maru Gothic (SIL OFL 1.1)


