跳到主要内容
食谱编号45

排版食谱 · 第3章 · 标题与章首页

旁标题、悬挂编号与段内标题

一份竞赛任务书:节标题立在页边的旁栏里,与正文基线对齐;小节编号悬挂在栏间距中,段内标题用红色。

本页内容
  • 英文样例:尚无中文版本
  • 成品尺寸210 × 297 mm
  • 一栏半, 栏间距7 mm
  • Mona Sans 10/14
  • DM Mono
  • Mona Sans@tnum
  • Noto Serif Display
  • 5页
  • 难度
  • Postext 1.65.0
  • 排版用时86 ms
  • 263行代码

简单来说

一份市政府的设计竞赛任务书,要把旧鱼市改成图书馆。各节标题放在左边宽宽的页边里,和旁边正文的第一行对齐。

成品一览

一份五页A4的建筑设计竞赛任务书:虚构的西班牙港口城镇Puerto Lince的市政府征集方案,要把1931年建成的鱼市改造成镇图书馆。版面仿照瑞士的市政报告。每页左侧有一条50 mm宽的旁栏,每一节都以一个红色编号和一道横贯整个版心的黑线开始。节标题用Noto Serif Display立在旁栏中,与正文第一行对齐。小节编号用红色DM Mono悬挂在栏间距中,因此每个小节标题都与正文左边缘对齐。第4节的评审标准以红色粗体词语开头。第1页在一幅总平面图上方排了58 pt的标题,第2页的旁栏中有一幅地块平面图,第3页以码头一侧的立面图开头。

这道食谱解答

  • 怎样给标题编号(1、1.1、1.1.1),并给每一级设置不同样式?
  • 怎样做一栏半版式,一个宽的正文栏加一个窄的侧栏?
  • 怎样控制图的位置:页面顶部、横跨两栏、就放在这里,还是放在边栏里?
  • 怎样给正文或框里的关键词(粗体或斜体)着色?

简短回答

script.js · 第56–81行在完整代码中
// The heading stays in the flow and keeps its number, but its design has no {titleText}:
// it prints the number in the channel and a rule from there to the column's right edge,
// both reserve: false, or the box below would keep a float gap under them (a line lower).
const [NUMBER, RULE] = [8.5, 0.75]; // pt: the DM Mono number, whose figures are 0.7 em tall
// Centre the rule on the figures: their baseline is 0.8 of the line down, less 0.35 em.
const RULE_Y = pt(NUMBER * (0.8 - 0.7 / 2) - RULE / 2);
const h2 = { level: 2, numberingTemplate: '{2}', lineHeight: pt(LEAD), // one grid line
  marginTop: pt(2 * LEAD), marginBottom: pt(0), advancedDesign: { enabled: true, slot: {
    elements: [
      { kind: 'text', id: 'number', content: '{number}', fontFamily: LABEL, fontWeight: 500,
        fontSize: pt(NUMBER), lineHeight: 1, color: col('signal'), reserve: false,
        placement: at('container', 'top-left', mm(-HANG)) },
      { kind: 'rule', id: 'rule', direction: 'horizontal', thickness: pt(RULE), reserve: false,
        color: col('ink'), placement: { ...at('#number', 'right-of', mm(2), RULE_Y),
          size: { width: 'fill' } } },
    ] } } };
// The title goes in a box fenced right after the heading: span="side" stands it in the
// channel on the grid line where the text resumes (gotcha: side-box-starts-at-fence).
// Attributes at the end of the line stay with the heading.
const sideHeads = (md) => md.replace(/^## (.+?)(\s*\{[^}]*\})?$/gm,
  (line, title) => `${line}\n\n:::callout{type="sidehead" span="side"}\n${title}\n:::`);
// The box has no background and no padding, and it takes the text's leading, so each
// line of the title sits on a baseline of the text beside it.
const sidehead = { id: 'sidehead', backgroundEnabled: false,
  padding: { top: pt(0), right: pt(0), bottom: pt(0), left: pt(0) },
  body: { fontFamily: DISPLAY, fontSize: pt(13.5), lineHeight: pt(LEAD) } };

用料

类型
Mona Sans, Noto Serif Display, DM Mono(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 用旁栏中的一个框印出节标题

代码见上面的简短回答。标题会为其版面设计中最低的那个元素预留空间,所以如果在旁栏中画一个与本节第一行对齐的标题,正文会被推下一行,两行的标题则推下两行。因此标题的版面设计只画编号和分隔线,而sideHeads()把每个## Title的文字复制到紧随标题之后的一个:::callout中。设为span="side"后,这个框脱离正文流,立在旁栏中正文接续的那条网格线上(标注框样式)。编号和分隔线设了reserve: false:否则旁栏中的框会在立于旁栏的标题元素下方留出一行的浮动间距,标题就会落到正文的第二行。框和正文都把一行的基线放在行高的0.8处,所以按正文14 pt行距排的框,会让两行标题的每一行都落在旁边段落某一行的基线上。Markdown仍是普通的## Schedule of accommodation。由于标题的版面设计没有印{titleText},沙盒会列出警告未引用标题文字,尽管框里印出了标题。

Page 2: the number and the rule come from the heading, the title from the box in the channel, level with the first line of the text. The plot plan stacks under it.

#2 · 旁栏只留给标题和图

script.js · 第46–52行在完整代码中
const layout = {
  layoutType: 'oneAndHalf',
  sideColumnPercent: (SIDE / CONTENT) * 100, // 50 of the 178 mm between the margins
  sideColumnSide: 'left', // on every page: the brief is printed on one side of the sheet
  sideColumnRole: 'floats', // no text in the channel: what span: 'side' sends, side captions
  gutterWidth: mm(GUTTER),
};

sideColumnRole: 'floats'让正文不进入旁栏(版式类型)。首页之后,旁栏中只有六个节标题和地块平面图(都用span: 'side'送进去),以及表1和表2的题注。旁栏默认为'right'(右侧),单面印刷的任务书在每页都把它放在同一侧。sideColumnSide: 'left'把它放到左边,这样每个节标题都在其正文之前被读到。

#3 · 悬挂编号,并把最低一级标题排成段内标题

script.js · 第85–102行在完整代码中
// The title keeps the text's left edge; the number, right-aligned in a 12 mm box, ends
// 2 mm short of it. The box needs that fixed width: an 'auto' width is clamped to the
// column and would shrink to nothing out here.
const H3 = { size: 10.5, number: 9 }; // pt; two boxes one grid line tall share a baseline
const h3 = { level: 3, numberingTemplate: '{2}.{3}', fontSize: pt(H3.size),
  lineHeight: pt(LEAD), marginTop: pt(LEAD), marginBottom: pt(0),
  advancedDesign: { enabled: true, slot: { elements: [
    { kind: 'text', id: 'title', content: '{titleText}', fontFamily: TEXT, fontWeight: 600,
      fontSize: pt(H3.size), lineHeight: LEAD / H3.size, color: col('ink'), align: 'left',
      overflow: 'wrap', placement: { ...at('container', 'top-left'), size: { width: 'fill' } } },
    { kind: 'text', id: 'number', content: '{number}', fontFamily: LABEL, fontWeight: 500,
      fontSize: pt(H3.number), lineHeight: LEAD / H3.number, color: col('signal'),
      align: 'right', placement: { ...at('#title', 'left-of', mm(-2)),
        size: { width: mm(12) } } },
  ] } } };
// Level 4 is not a heading: '**Accessibility.** A wheelchair user…' opens its paragraph.
// No other paragraph has bold; table cells keep tableStyle's ink, so Total stays black.
const runIn = { boldColor: col('signal') }; // spread into bodyText

小节标题从栏的左边缘开始。它的编号以'left-of'锚定在标题左侧,在一个12 mm宽、距正文2 mm处结束的框中右对齐,所以2.1、3.3这样的编号悬挂在栏间距中,每个标题都与下面的正文对齐(元素定位)。这个框需要固定宽度。'auto'宽度会被限制在栏内,放到栏间距里就一点宽度也不剩,编号也就画不出来。第2级印'{2}',第3级印'{2}.{3}',因为用{1}的话,每个编号都会以任务书唯一那个H1的1开头。第4节的评审标准是不用标题排的第四级。每段以一个粗体词语开头,bodyText.boldColor把它印成红色(正文)。其他段落都没有粗体,表格单元格的颜色取自tableStyle,所以表1加粗的Total行仍是黑色。

#4 · 为每个图和表分别指定位置

script.js · 第335–369行在完整代码中
// The plot plan stands in the channel; the elevation crosses channel and column at the
// head of the next page; the table of areas floats to the head of the text column, with
// its caption beside it in the channel; the timetable sits where ::resource puts it, and
// its caption takes the channel too (captionSide serves an inline embed from 1.28).
const PLAN_W = 44; // mm: the plot plan, 88 m wide at 1:2000
const resource = (id, typeId, rest) => ({ id, typeId, createdAt: 0, updatedAt: 0, ...rest });
const drawing = (id, width, height, rest) => resource(id, 'figure', { kind: 'svg',
  svg: { fileId: `${id}.svg`, width, height }, ...rest });
const resources = [
  drawing('parcela', PLAN_W * 10, 400, {
    placement: { span: 'side', width: PLAN_W / SIDE }, // 44 mm of the channel's 50
    caption: t({ en: 'The plot, 1:2000. Market hall and weighbridge hut in grey; six tamarisks '
      + 'along the north edge. Red arrows: possible entrances; grey arrow: service.',
    es: 'La parcela, 1:2000. Lonja y caseta de básculas, en gris; seis tamarindos en el '
      + 'borde norte. Flechas rojas: accesos posibles; flecha gris: servicio.' }),
    altText: t({ en: 'Plan of the plot with the hall, the hut, six trees and three entrances.',
      es: 'Planta de la parcela con la lonja, la caseta, seis árboles y tres accesos.' }) }),
  drawing('fachada', 1780, 300, { placement: { position: 'top', span: 'page' },
    caption: t({ en: 'Quay front, 1:300. In red, the four frames at the east end, where the '
      + 'reinforcement has corroded.',
    es: 'Fachada al muelle, 1:300. En rojo, los cuatro pórticos del extremo este, con '
      + 'las armaduras corroídas.' }),
    altText: t({ en: 'Elevation of the hall: thirteen vaults, eleven arches, four frames in red.',
      es: 'Alzado de la lonja: trece bóvedas, once arcos y cuatro pórticos en rojo.' }) }),
  resource('programa', 'table', { kind: 'table', table: { ...programme, styleId: 'figures' },
    placement: { position: 'top', captionSide: true }, caption: t({
      en: 'Schedule of net floor areas.', es: 'Programa de superficies útiles por zonas.' }) }),
  resource('calendario', 'table', { kind: 'table', table: calendar,
    placement: { position: 'here', captionSide: true },
    caption: t({ en: 'Competition timetable.', es: 'Calendario del concurso.' }) }),
  // No :ref cites the site plan: only the opener's image element draws it.
  drawing('situacion', MAP.w * 10, MAP.h * 10, { altText: t({
    en: 'Site plan of the Poniente quay with the market hall’s plot in red.',
    es: 'Plano de situación del muelle de Poniente con la parcela de la lonja en rojo.' }) }),
];

地块平面图用span: 'side'放进旁栏,叠在第2节的旁标题下方(定位)。width: PLAN_W / SIDE让它宽44 mm,88米的地块恰好是1:2000。立面图是横贯页面的'top'浮动体。它在第2页被引用,排在第3页开头,因为浮动体从不排在其引用位置之前。功能需求表同样在第2页被引用,浮动到第3页正文栏的顶部,排在立面图下方。captionSide: true让它的题注立在旁栏中,与表格顶部对齐。日程表放在::resource所在的位置,即任务书末尾,captionSide: true同样让它的题注立在旁栏中,在6.3小节旁边。Mona Sans默认使用比例数字,右对齐的一栏里120和560的各位数字对不齐。命名表格样式tableStyles: [{ id: 'figures', figureStyle: 'tabular' }]由表1用styleId: 'figures'选用,启用字体的tnum:它的等宽数字带斜线零,与DM Mono的编号相近。日程表中的日期保留字体自身的数字(数字样式)。

#5 · 以总平面图开启任务书

script.js · 第106–131行在完整代码中
const MAP = { y: 68.5, w: CONTENT, h: 52 }; // mm: from the top of the text block
const display = { fontFamily: DISPLAY, fontWeight: 300, color: col('ink'), align: 'left',
  overflow: 'wrap' };
const opener = { enabled: true,
  // The plan's foot falls between two grid lines. A floor on the next one leaves the rule
  // of section 1 as far from its text as the rule of every later section.
  minHeight: mm(GRID * Math.ceil((MAP.y + MAP.h) / GRID)),
  slot: { elements: [
    { kind: 'text', id: 'kicker', content: '{attr.kicker}', ...label, color: col('signal'),
      placement: at('container', 'top-left', mm(HANG)) },
    { kind: 'text', id: 'series', content: '{subtitle}', ...label,
      placement: { ...at('container', 'top-left'), size: { width: mm(SIDE) } } },
    { kind: 'text', id: 'title', content: '{titleText}', ...display, fontSize: pt(58),
      lineHeight: 0.96, placement: { ...at('#kicker', 'below', mm(0), mm(4.5)),
        size: { width: mm(MAIN) } } },
    { kind: 'text', id: 'lead', content: '{attr.lead}', ...display, italic: true,
      fontSize: pt(14), lineHeight: 1.3, placement: { ...at('#title', 'below', mm(0), mm(5)),
        size: { width: mm(MAIN) } } },
    { kind: 'text', id: 'legend', content: '{attr.map}', fontFamily: TEXT, fontSize: pt(7.5),
      lineHeight: 1.4, color: col('muted'), align: 'left', overflow: 'wrap',
      placement: { ...at('#lead', 'align-top', mm(-HANG), pt(2)),
        size: { width: mm(SIDE - 6) } } },
    { kind: 'image', id: 'map', resourceId: 'situacion', // across the channel and the column
      placement: { ...at('container', 'top-left', mm(0), mm(MAP.y)),
        size: { width: mm(MAP.w) } } },
  ] } };

设为span: 'page'时,首页标题的容器是整个版心,包括旁栏(span与高级版面设计)。眉题和标题放在57 mm处,即正文栏的左边缘,平面图横跨旁栏和正文栏。不设时,容器是正文栏,所有元素右移57 mm,标题、导语和平面图都会超出页面右边缘。版面设计预留的空间一直到平面图底部,而这个位置落在两条网格线之间。把minHeight向上取整到下一条网格线后,第1节的分隔线与正文的距离和后面每一节都相同。眉题、导语和图例都是# Competition brief这一行的属性。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 045 · Side heads, hanging numbers and run-in heads ═══════
// https://postext.dev/en/cookbook/side-heads-hanging-numbers
// Code: MIT · Text: original (CC BY 4.0) · Drawings: made in code (MIT)
// Fonts: Mona Sans, Noto Serif Display, DM Mono (SIL OFL 1.1) · Needs postext ≥ 1.65.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, defaultResourceTypes,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'side-heads-hanging-numbers';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { // a Swiss municipal report: black, white and one signal red
  ink: '#17171a', // text and rules
  signal: '#d42a1f', // section numbers, run-in heads, the plot on the plans (5.1:1)
  tint: '#f9dcd7', // the plot's ground on the plans
  sea: '#d8e2e8', // water on the plans
  stone: '#cacad0', // built ground on the plans
  rule: '#c3c3ca', // hairlines under the running head and in tables
  muted: '#5e5e67', // running heads, legends, the colophon (6.4:1)
  paper: '#ffffff',
};
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// Defaults this config does not restate link to 'main-color', so it points at the accent.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.signal })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, DISPLAY, LABEL] = ['Mona Sans', 'Noto Serif Display', 'DM Mono'];
const TRIM = { width: 210, height: 297 }; // mm: A4, like every document of the competition
const [TOP, LEFT, RIGHT] = [26, 16, 16]; // mm; not mirrored: the brief prints one-sided
const LEAD = 14; // pt: the body leading, the pitch of the baseline grid
const LINES = 50; // grid lines in the text block
const PT = 25.4 / 72; // mm in a point
const GRID = LEAD * PT; // mm: one line of the grid
const CONTENT = TRIM.width - LEFT - RIGHT; // 178 mm
const [SIDE, GUTTER] = [50, 7]; // mm: the margin channel on the left, and the gap after it
const MAIN = CONTENT - SIDE - GUTTER; // 121 mm: the text column
const HANG = SIDE + GUTTER; // mm from the channel's left edge to the text's left edge
const at = (to, edge, x = mm(0), y = mm(0)) => ({ anchor: { to, edge }, offset: { x, y } });
// Kickers, running heads and folios: tracked capitals in the mono.
const LABEL_PT = 7.5;
const label = { fontFamily: LABEL, fontWeight: 500, fontSize: pt(LABEL_PT), lineHeight: 1.35,
  letterSpacing: pt(1.2), textTransform: 'uppercase', color: col('muted'), align: 'left' };

// #region channel: one text column, and on its left a channel for boxes and figures only
const layout = {
  layoutType: 'oneAndHalf',
  sideColumnPercent: (SIDE / CONTENT) * 100, // 50 of the 178 mm between the margins

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

变化

#分隔线只画在正文栏

把分隔线锚定在标题自身的框上而不是编号上,它就从正文左边缘画到栏的右边缘,旁栏中只剩编号和标题。

-        color: col('ink'), placement: { ...at('#number', 'right-of', mm(2), RULE_Y),
+        color: col('ink'), placement: { ...at('container', 'top-left', mm(0), RULE_Y),

常见问题

易错点

侧栏框与其围栏之后的块齐平开始

在postext 1.4.1中,span: 'side'的框在侧栏中的位置,是正文排到其围栏处时的高度,落在下一个网格行上,并排在已在那里的框之下。把旁注围在它所解释的段落之前:围在段落之后,旁注就会从下一段旁边开始。会超出栏底的框会向上滑,在上方框允许的范围内,直到底边落在栏底;仍然放不下的,就等到下一页的侧栏。 旁注 →

易错点

'top'浮动体默认排在引用页的下一页,除非允许它置于引用页顶

默认情况下浮动体不会排在自己的引用之前,所以在第N页引用的整页宽'top'浮动体会出现在第N+1页的顶部。在资源或其类型的defaultPlacement上设置placement.citingPage: true(或者对全书设置layout.floatsAtCitingPage,自postext 1.25起),它就改为置于第N页顶部,引用处之上的文字移到它下方,前提是它不超过layout.maxTopFraction且引用行仍留在该页。它不会置于章首页或强制分页之后的页面顶部:那时仍排在下一页,而'auto'或'bottom'可以占用引用页的底部。 图的放置 →

沙盒检查 · headingAdvancedWithoutTitleText

标题文字未印出

原因. 某个高级设计中没有任何元素印出{titleText},因此标题本身的文字永远不会出现。

解决. 加一个带{titleText}的文字元素,除非这个标题本来就应该不可见。 文档 →

  • 旁栏中的图会占据引用它那一页旁栏的顶部,排在它之后的旁标题会叠在图下方,低于本节的开头。旁栏中的图要在其所在页的节标题之后引用,就像第2节引用地块平面图那样。
  • 自postext 1.28起,行内嵌入(position: 'here')也接受captionSide:日程表的题注立在第5页的旁栏中,和第3页功能需求表的题注一样。题注需要表格旁边的旁栏空着。那里已有旁标题或旁栏图时,题注留在表格下方。

致谢

文本
原创文字, CC BY 4.0
字体
Mona Sans (SIL OFL 1.1) · Noto Serif Display (SIL OFL 1.1) · DM Mono (SIL OFL 1.1)
沙盒