かんたんな説明
日本の全集が刷るように短編2編を組みます。文字は上下に重ねた2つの帯の中を縦に流れ、各編は左ページで始まって題がページの高さいっぱいに立ち、最終ページは上下の帯の長さをそろえません。
できあがり
右綴じのA5判の全集から取った7ページです。芥川龍之介の『蜘蛛の糸』と『尾生の信』を、1段25字、横に21行の二段組みに組みます。Noto Serif JPの9ptで、段のあいだに細い罫を引きます。各編は奇数ページ、つまり左ページで始まり、20ptの題が2段を通して縦に立ち、地の近くに作者名が入ります。ノンブルは211ページから続きます。節の一、二、三はその段の3行を取ります。作品が終わると、最終ページは本文が流れたままにします。これが成り行きです。214ページでは作品が日付とともに上段で終わり、上段は1行を残し、下段は空のままです。中国語の縦組みの段組みの新聞はNo. 084、横組みの2段に章題を通す例はNo. 017にあります。
このレシピが答える質問
- 章タイトルをページ幅いっぱいに置き、その下で本文を2段組みにするには?
- 改ページや改段を強制し、すべての章を右ページから始めるには?
- 版面を字数で設定し、1行の字数と1ページの行数を決めるには?
手短な答え
// 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段組みと2段組み縦組み段末そろえ右綴じの本奇数ページから始まる章行取りの見出し文字グリッド段間罫日本語の改行(禁則処理)日本語の約物のアキふりがな:漢字に付ける仮名の読み青空文庫の取り込み中国語・日本語・韓国語のフォント柱とノンブルページの役割ごとの柱見出しスタイルデザインした章扉段落スタイルセマンティックカラーパレットPDFの書き出し
- 種類
- Noto Serif JP, Noto Sans JP (SIL OFL 1.1)
- 素材
- なし:画像はすべてコードで描画
作り方
#1 · 90度回した2段は、上下の2段になる
コードは上の手短な答えにあります。writingMode: 'vertical-rl'のページでは、layoutType: 'double'は2つの段を上下に重ねます。1段目は上段を右から埋め、次に下段に移り、段間は2段のあいだの帯になります(縦組み)。文字グリッドは1段の中の縦の字数を数えるので、各段は9ptの文字25字で、段間はちょうど2字分に丸められます。横に並ぶ15.75ptの21行は、148mmのページのうち116.7mmに収まります。段のあいだの罫はページを横切り、暖かいグレーの0.4ptです。
Postextの段末そろえは、作品の最終ページの2段を同じ行で終わらせようとします。中国語の新聞やヨーロッパの2段組みの本の多くは、章をそうして閉じます。日本語の段組みの本は本文を成り行きに任せ、上段がページいっぱいに続いてから下段が始まります。balancing.trailing: falseがその選択です。縦組みの段は、enabled: trueで段末そろえをオンにしない限り、そもそもそろえられません(段末そろえ)。
#2 · 作品の題を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'を付けた見出しレベルは、ページの高さ全体、つまり2つの段と段間にまたがって、流れの先頭、縦組みのページでは右端に組まれます。段はそのデザインが確保する7行のあとから始まります。このような見出しは必ずページを改め、breakBefore.parity: 'odd'がそれを左ページにします。『蜘蛛の糸』は偶数ページの214ページで終わるので、『尾生の信』は白ページを挟まずに215ページで始まります(幅と詳細デザイン)。デザインでは、xはページを下へ、yは版面の右端から横へ進みます。作者名は下段の地から3字上に置きます。
#3 · 節番号はその段の3行取り
レベル2はlineSpan: 3とindent: em(8)で、一、二、三を段の8字下げの位置に3行幅の帯で組みます。青空文庫のテキストの指定(八字下げ、中見出し)どおりです。これで節番号のあとの本文も、隣の段の行に乗ったままになります(レベルごとの上書き)。作品を締めくくる日付「(大正七年四月十六日)」は、:::paragraphs{align=end endIndent=1}で段の地から1字上げます(地から一字上げ)。青空文庫の変換スクリプトはこれを地にそろえるaozora-end1スタイルとして書き出し、開始行の属性が1字上げを加えます。
#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'で作品の始まるページからはどちらも外します(縦組みのテキスト要素)。ノンブルは、多くの全集の刷り方にならい、余白を横切るようにアラビア数字で組みます。小口に沿って縦に組むと、3桁の数字が横倒しになってしまうからです。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行で終わります。中国語やヨーロッパの段組みの本が使う終わり方です。文字グリッドでは段末そろえが足すのは行単位だけなので、どの字も自分のマスから動きません。
-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' } };#作品を1段で組む
長編小説や文庫は本文を段間なしの1段で組みます。No. 117はそのように文庫を組んでいます。
よくあるつまずき
つまずき
日本語のテキストのタグは'ja'。zh-HansやLANGにしない
レシピの版はenとesですが、日本語のサンプルはどちらの版でも日本語です。`locale: LANG`では英語やスペイン語とタグ付けされ、中国語のタグでは中国語の規則で組まれます(開明式の約物、小書きの仮名が行頭に来てもよい、図の代わりに图、PDFでは中国の字形)。postext 1.30以降、このタグはテキストを組む言語(計測、描画、埋め込みに使う言語)でもあるので、'ja'以外のタグでは日本語の字形ではなく別の字形(中国語のタグでは中国の字形)になり、改行の位置も変わります。'ja'と書いてください。日本の地域(JLReqの改行と約物、ゴマの圏点、ルビの間隔、図と表の表示名)が選ばれ、ハイフネーションが切られます。リントは、zhやkoのタグで仮名を含むテキストをエラーにします。 日本語の改行(禁則処理) →
つまずき
ページ幅の見出しは必ず新しいページを始める
階層やスタイルでspan: 'page'を設定した見出しは、breakBeforeの有無にかかわらず、ページの頭の章扉として組まれます。ほかのテキストのあとや、同じページの別の章扉のあとに置くと、次のページに移り、現在のページの残りは空になります。題字の下で両段(縦組みのページなら上下両段)にまたがる大見出しは、題字と並べて章扉自身のデザインに入れるか、spanを指定しない見出しとして:::callout{span="page"}の囲みに入れてください。newspaper-front-pageの大見出しはこの方法で組んでいます。 デザインした章扉 →
つまずき
中国語の書体はcjkブロックを通じてスライス単位で読み込む
Fontsourceは中国語、日本語、韓国語のファミリーを、ウェイトごとに約100個のファイルとして配信し、各ファイルが文字の範囲を受け持ちます。loadFontsが取得するのはlatinファイルだけなので、画面では漢字がシステムの書体で出て計測が狂い、fontsourceProviderはPDFにそのlatinファイルを渡すため、漢字が空の四角で印字されます。キットのcjkブロックを挙げ、loadFontsのあとにloadCjkFonts(FONTS, markdown)を呼び(本で複数のCJK書体を使うときは、それぞれの書体で組むテキストを渡して書体ごとに1回)、renderToPdfにfontProvider: cjkPdfProviderを渡してください。どちらもテキストの文字を含むファイルを取得します。 中国語・日本語・韓国語のフォント →
つまずき
右綴じの本の見開きはshowBookで表示する
右綴じの本(アラビア語、ヘブライ語、ペルシア語のテキスト、縦組みの中国語、またはpage.binding 'right')でも1ページは奇数ページですが、背の左側に来て、見開きは[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)


