跳到主要内容
食谱编号71

排版食谱 · 第6章 · 框与注释

脚注排在引用它的那一栏底部

Markdown的[^id]标记变成编号注释,排在引用它的那一栏底部;另有开关可切换为单栏、章末注和连续编号。

本页内容
输出
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页

  • 英文样例:尚无中文版本
  • 成品尺寸210 × 280 mm
  • 2栏, 栏间距7 mm
  • EB Garamond 10.5/13.5
  • Bodoni Moda
  • IBM Plex Sans Condensed
  • 3页
  • 难度
  • Postext 1.65.0
  • 排版用时28 ms
  • 164行代码

简单来说

一本西班牙古典小说《Lazarillo de Tormes》的学生版,分两栏排。示例演示怎样把每条注释放在引用它的那一栏底部,读者不必翻页就能看到。

成品一览

《Lazarillo de Tormes》(《小癞子》)的学生版,开本210 × 280 mm,用EB Garamond排成两栏:包括序言和第一章的开头,Lázaro生在托尔梅斯河上的一座磨坊里,后来跟着一个瞎子出门闯荡。注释解释1554年的读者知道而今天的读者不知道的事:Tejares村、远征Los Gelves岛、萨拉曼卡桥头的石牛。每条注释都排在引用它的那一栏底部,字号更小,在一条深红色短线之下,所以视线从注码落到注释再回来,不用翻页。英文版用的是Clements Markham在其1908年译本中自己写的注释。

这道食谱解答

  • 脚注怎么做?

简短回答

script.js · 第42–54行在完整代码中
// In the Markdown: `Tejares,[^9]` cites a note (the id may be a word: `[^tejares]`), and
// a paragraph that opens with `[^9]:` anywhere in the chapter defines it. The engine
// numbers the notes in order of citation and keeps each note in the column of the line
// that cites it: a line whose note does not fit under it moves on with the note.
const footnotes = () => ({
  placement: options.placement, // 'column' (the foot of the citing column) or 'chapterEnd'
  numbering: options.numbering, // 'chapter': 1, 2, 3… again under every chapter heading
  fontSize: pt(8.5), // off the baseline grid: the notes stack up from the column's foot
  lineHeight: pt(10.5),
  hangingIndent: em(0.9), // turnover lines align past the number
  spaceBetween: pt(1.5),
  separator: { width: 0.25, lineWidth: pt(0.5), color: col('oxblood') },
});

用料

类型
EB Garamond, Bodoni Moda, IBM Plex Sans Condensed(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 在该引用的地方引用,定义写在哪里都行

配置见上面的简短回答,其余都是Markdown。natives of Tejares,[^9]印出一个紧贴逗号的上标数字,以[^9]:开头的段落是注释内容。不管定义写在哪里,都会离开正文流,所以这个示例把它们全放在章末,和Markham的注释在源文件中的位置一样。编号按引用顺序生成,所以Markdown中的id可以是单词(西班牙语版用[^tejares]),给一章重新编号时也不必修改注释。

#2 · 给栏留出注释的位置

排每一行之前,版面会加上这一行首次引用的注释的高度;如果这是本栏的第一条注释,还要加上分隔线。某一行的注释在它下方放不下时,这一行连同其段落移到下一栏,同时遵守段首孤行和段末孤行规则,所以注码永远不会指向另一栏的注释。注释用自己的字号和行距从栏底往上堆叠,不在基线网格上,而上方的正文仍在网格上;各栏齐底只计算正文。

#3 · 让每个章首页下沉到同一行

script.js · 第58–76行在完整代码中
const opener = {
  enabled: true,
  // The sink holds a two-line title and its rule, with ~8 mm to the first line of text,
  // so every chapter starts on the same grid line whatever its title's length.
  minHeight: pt(LEAD * 10),
  slot: { elements: [
    { kind: 'text', id: 'kicker', content: '{attr.kicker}', ...label, fontSize: pt(8.5),
      letterSpacing: pt(1.8), color: col('oxblood'), align: 'center',
      placement: at('container', 'top', 0, 7) },
    { kind: 'text', id: 'title', content: '{titleText}', fontFamily: 'Bodoni Moda', italic: true,
      fontSize: pt(26), lineHeight: 1.1, color: col('ink'), align: 'center',
      overflow: 'wrap', // design text ends in an ellipsis by default
      placement: { ...at('container', 'top-left', 0, 13),
        size: { width: 'fill', height: 'auto' } } },
    { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(0.75), color: col('oxblood'),
      placement: { anchor: { to: '#title', edge: 'below' }, // a rule starts at the box's left
        offset: { x: mm((MEASURE - 14) / 2), y: mm(4.5) }, size: { width: mm(14) } } },
  ] },
};

章首页横跨两栏,章节眉题取自标题的kicker属性。minHeight预留十条网格线,足够放两行Bodoni标题和它下面的线,所以每章正文都从同一行开始,这条线也不会落在正文第一行上。

#4 · 左页印书名,右页印章名

script.js · 第80–97行在完整代码中
const head = (id, content, parity, edge, x, extra = {}) => ({
  kind: 'text', id, content, parity, pages: 'body', // never on openers
  ...label, fontSize: pt(7.5), letterSpacing: pt(1.3), color: col('muted'),
  placement: at('page', edge, x, 13), ...extra,
});
const folio = { color: col('oxblood') };
const header = { elements: [
  head('verso-folio', '{pageNumber}', 'even', 'top-left', MARGIN.outer,
    { ...folio, align: 'left' }),
  head('verso-title', '{title}', 'even', 'top-left', MARGIN.outer + 9, { align: 'left' }),
  head('recto-title', '{chapterTitle}', 'odd', 'top-right', -(MARGIN.outer + 9),
    { align: 'right', overflow: 'ellipsis' }),
  head('recto-folio', '{pageNumber}', 'odd', 'top-right', -MARGIN.outer,
    { ...folio, align: 'right' }),
] };
// Openers carry a drop folio instead, centred under the text block.
const footer = { elements: [{ ...head('drop-folio', '{pageNumber}', 'all', 'bottom', 0,
  { ...folio, align: 'center', placement: at('page', 'bottom', 0, -11) }), pages: 'opener' }] };

书眉按奇偶锚定在页面上,页码在外侧;pages: 'body'让它们不出现在章首页上,章首页改为在页脚居中印页码。章名过长时在120 mm处以省略号结束,不会碰到页码。

#5 · 试试其他位置

script.js · 第202–230行在完整代码中
const CHOICES = {
  columns: [[2, t({ en: 'Two columns', es: 'Dos columnas' })],
    [1, t({ en: 'One column', es: 'Una columna' })]],
  placement: [['column', t({ en: 'Column foot', es: 'Pie de columna' })],
    ['chapterEnd', t({ en: 'End of chapter', es: 'Final del capítulo' })]],
  numbering: [['chapter', t({ en: 'Per chapter', es: 'Por capítulo' })],
    ['document', t({ en: 'Continuous', es: 'Continua' })]],
};
const bar = document.createElement('form');
bar.id = 'options';
bar.ariaLabel = t({ en: 'Footnote options', es: 'Opciones de las notas' });
for (const [key, choices] of Object.entries(CHOICES)) {
  const group = bar.appendChild(document.createElement('fieldset'));
  for (const [value, text] of choices) {
    const input = Object.assign(document.createElement('input'), { type: 'radio', name: key,
      value: String(value), checked: options[key] === value });
    const item = group.appendChild(document.createElement('label'));
    item.append(input, text);
  }
}
bar.addEventListener('change', (event) => {
  const { name, value } = event.target;
  options[name] = name === 'columns' ? Number(value) : value;
  config.layout = layoutFor(options.columns); // changed in place: the build sees it
  config.footnotes = footnotes();
  doc = buildDocument({ markdown }, config); // the fonts are loaded by now
  showPages(doc, { title: TITLE });
});
document.getElementById('pages').before(bar);

每个开关都改动一个选项,重新构建这一章。单栏把注释排在页面底部,单栏时页面底部就是栏底。章末把注释排在本章最后一段之后,并下沉到它们所在那一栏的底部,上方是同样的线。Continuous让编号从序言一直延续到第一章,而不是从1重新开始。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 071 · Footnotes at the foot of the column ══════════════
// https://postext.dev/en/cookbook/novel-footnotes-column-foot
// Code: MIT · Text: Lazarillo de Tormes (1554) and Markham's 1908 translation (PD)
// Fonts: EB Garamond, Bodoni Moda, IBM Plex Sans Condensed (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import { buildDocument, buildDocumentWithFonts, renderPageToCanvas } 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 = 'novel-footnotes-column-foot';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: oxblood for the kickers, the folios and the notes' rule; ink on warm paper
const palette = {
  ink: '#241e1a', // text: a warm near-black
  oxblood: '#7d2b1f', // the one accent
  muted: '#6f655b', // running heads, colophon
  rule: '#c9bdae', // hairlines
  paper: '#fbf8f2',
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the id.
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' } })),
  // The engine's defaults link to main-color: point it at the accent, never the default blue.
  { id: 'main-color', name: 'accent (defaults)', value: { hex: palette.oxblood, model: 'hex' } },
];
// #endregion
const TRIM = { width: 210, height: 280 }; // a school edition: two 82 mm columns
const MARGIN = { top: 23, bottom: 22, inner: 21, outer: 17 }; // mirrored
const MEASURE = TRIM.width - MARGIN.inner - MARGIN.outer; // 172 mm
const LEAD = 13.5; // body leading in pt: the baseline grid
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const label = { fontFamily: 'IBM Plex Sans Condensed', fontWeight: 600,
  textTransform: 'uppercase' };

// The switches under the title change these and build again (#region live).
const options = { columns: 2, placement: 'column', numbering: 'chapter' };
const layoutFor = (columns) => (columns === 2
  ? { layoutType: 'double', gutterWidth: mm(7) } : { layoutType: 'single' });

// #region answer: the notes at the foot of the column that cites them
// In the Markdown: `Tejares,[^9]` cites a note (the id may be a word: `[^tejares]`), and
// a paragraph that opens with `[^9]:` anywhere in the chapter defines it. The engine
// numbers the notes in order of citation and keeps each note in the column of the line
// that cites it: a line whose note does not fit under it moves on with the note.
const footnotes = () => ({
  placement: options.placement, // 'column' (the foot of the citing column) or 'chapterEnd'
  numbering: options.numbering, // 'chapter': 1, 2, 3… again under every chapter heading

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

变化

#让章末注紧跟正文

设置placement: 'chapterEnd'时,注释默认排在最后一栏的底部;chapterEndAlign: 'text'把它们排在最后一段的正下方。

   placement: options.placement,
+  chapterEndAlign: 'text',

#去掉分隔线

没有分隔线时,注释仍靠spaceAbove和spaceBelowRule与正文隔开。

-  separator: { width: 0.25, lineWidth: pt(0.5), color: col('oxblood') },
+  separator: { enabled: false },

常见问题

易错点

章首页预留的高度一直到最低的页面锚定元素

高级设计的章首页会预留到其最低元素为止的高度,标题下方锚定在页面或出血上的元素也算在内,所以页脚处的装饰会把正文推到下一页。给这样的元素设reserve: false(从postext 1.5起):它绘制在锚定的位置,不预留任何空间。跟随区段本身的元素(锚定在区段底边,或高度为'fill')从不决定区段的高度。 设计过的章首页 →

版面警告 · undefinedFootnote

脚注没有定义

原因. 某个[^id]标记引用的脚注没有对应的[^id]:段落来定义,因此注码指向一条空脚注。

解决. 加一个写有注文的[^id]:段落,或改正标记的id。 文档 →

版面警告 · unusedFootnote

脚注未被引用

原因. 某个[^id]:定义在正文中没有标记,因此这条脚注不会排出。

解决. 在合适的位置用[^id]引用它,或删除这条定义。 文档 →

  • 题注、表格单元格或标题中的标记会原样印出:只有段落、列表项、引文和框里的注释标记会被识别。
  • 注释从不跨栏拆分:比栏还高的注释会超出栏底。像编辑们那样,把每条注释控制在几行之内。

致谢

文本
  • La vida de Lazarillo de Tormes, Burgos edition of 1554: the prologue and the beginning of the first treatise · Anonymous · 公有领域
  • The Life of Lazarillo de Tormes, translated by Clements Markham (1908), with his notes: the prologue and the first chapter, abridged · Clements Markham · 公有领域
  • The Spanish notes, adapted from Markham's and written for this edition · Ignacio Ferro · CC BY 4.0
字体
EB Garamond (SIL OFL 1.1) · Bodoni Moda (SIL OFL 1.1) · IBM Plex Sans Condensed (SIL OFL 1.1)
沙盒PDF