In short
Chapter opening pages for a geology textbook. A coloured band with a big chapter number runs off the top edge of the page, and the design is set up once for every chapter.
What you'll build
The chapter openers of Earth in Motion, an introductory geology textbook on a 210 × 280 mm page. Chapter 3 opens under a terracotta band bled off the top of the page. The band carries a tracked kicker, the title broken where the author chose, an italic standfirst and a 168 pt chapter number that stands on the band's dark foot at the fore-edge. Two justified columns start under the band, and a cross-section of a sinking plate takes the foot of the page. Chapter 4 repeats the design in teal, down to the thumb tab, the section numbers, the references and the label of its figure. The design is set once, on the level-1 heading. Each chapter's heading line supplies the kicker's topic and the standfirst as attributes, and names a style when the chapter takes another colour.
This recipe answers
- How do I make a chapter opener with a full-bleed colour band, a big chapter number and the title?
- How do I set a chapter title across the page while the body runs in two columns below?
- How do I add an author line, a standfirst or a lead with a drop cap to an opener?
- How do I give every chapter its own photo, colour or opener variant?
- How do I number headings (1, 1.1, 1.1.1) and style each level differently?
The short answer
const TOP = 24; // top margin, mm: the opener's container starts here
const OUTER = 16; // outer margin, mm: the numeral and the folios line up on it
const BLEED = 0; // mm: 0 on screen; about 3 for print, which also switches on page.cutLines
const BAND = 100; // mm from the trim to the foot of the band
const NUMERAL = 168; // pt; the baseline of a design text sits 0.8 down its line box
const PT = 25.4 / 72; // mm in a point
const AIR = 12; // mm, foot to text: ≥ 0.2 × NUMERAL × PT ≈ 11.9, the numeral box below its baseline
const BEARING = 2; // mm past the text edge: a rough optical nudge, as each digit's bearing differs
const bleedTop = { to: 'bleed', edge: 'top-left' }; // the trim's corner, pushed out by BLEED
// Design text centres by default; in a heading design it wraps by default too.
const onBand = { color: col('paper'), align: 'left' };
const below = (id, y, width) => ({ anchor: { to: `#${id}`, edge: 'below' }, offset: { y: mm(y) },
size: { width: mm(width) } }); // chained: a longer title pushes the standfirst down
const opener = { enabled: true,
// The text starts below the lowest element or minHeight (gotcha: opener-reserves-anchored).
minHeight: mm(BAND - TOP + AIR), // clears the numeral, so the text starts AIR below the foot
slot: {
elements: [ // array order is paint order: the band first, the type on top
{ kind: 'box', id: 'band', style: { backgroundColor: col('band') }, placement: {
anchor: bleedTop, size: { height: mm(BLEED + BAND) } } }, // no width: runs to the far edge
{ kind: 'rule', id: 'foot', color: col('ink'), thickness: mm(1.6), placement: {
anchor: bleedTop, offset: { y: mm(BLEED + BAND) } } },
{ kind: 'text', id: 'numeral', content: '{chapterNumber}', ...onBand,
fontFamily: 'Archivo', fontWeight: 800, fontSize: pt(NUMERAL),
lineHeight: 1, // a box as tall as the type: the y below counts on it
placement: { anchor: { to: 'page', edge: 'top-right' }, // the fore-edge of a recto
offset: { x: mm(BEARING - OUTER), y: mm(BAND - 0.8 * NUMERAL * PT) } } }, // on the foot
{ kind: 'text', id: 'kicker', ...onBand, fontFamily: 'Archivo Narrow', fontWeight: 600,
content: `${t({ en: 'Chapter', es: 'Capítulo' })} {chapterNumber} · {attr.topic}`,
fontSize: pt(8.5), letterSpacing: pt(2), textTransform: 'uppercase',
placement: { anchor: { to: 'container', edge: 'top-left' }, offset: { y: mm(7) } } },
{ kind: 'text', id: 'title', content: '{titleText}', ...onBand, // breaks at the \\
fontFamily: 'Archivo', fontWeight: 800, fontSize: pt(34), lineHeight: 1.02,
placement: below('kicker', 3, 118) },
{ kind: 'text', id: 'lead', content: '{attr.lead}', ...onBand, fontFamily: 'Roboto Serif',
italic: true, fontSize: pt(10.5), lineHeight: 1.36, placement: below('title', 6, 100) },
],
},
}; // hook-up: headings.levels[0] = { span: 'page', breakBefore, advancedDesign: opener }
The opener: a bleed band, the numeral on its foot, texts from the heading
Ingredients
- Features
- Designed openersFull-width chapter bandHeading attributesLine breaks in titlesHeading stylesColours per partNumbered headingsChapters that open on a rectoAnchoring design elementsText, rules and boxes in page designsBleed bands and thumb tabsSemantic colour paletteRunning heads and foliosHeads by page roleCitations that place figuresFigure placementFigures and tables as resourcesBooks built chapter by chapterPages on a canvas
- Also uses
- Bleed and crop marksParagraph styles
- Type
- Roboto Serif, Archivo, Archivo Narrow (SIL OFL 1.1)
- Assets
- None: every picture is drawn in code
Method
#1 · Hang the band and the numeral from the page
The code is the short answer above. The band and its foot hang from the bleed's top-left corner. Like any box or rule given no width, they stretch to the far edge of that frame, so they reach the trim, and the bleed once BLEED is set. The numeral hangs from the page's top-right corner: y: BAND - 0.8 * NUMERAL * PT puts its baseline on the foot, and BEARING moves its box 2 mm into the margin to make up for the digit's side bearing, so the ink lines up roughly with the text edge. The kicker hangs from the container. The title hangs below the kicker and the standfirst below the title, through below anchors, and a heading design wraps its text by default, so a longer title pushes the standfirst down. The standfirst is a text element filled from the heading's lead attribute; an author line would be one more, {attr.author}, chained the same way. minHeight: BAND - TOP + AIR sets where the body starts. The numeral's box reaches 0.2 × its size (11.9 mm) below the foot, and an opener reserves space down to its lowest element, so AIR has to be at least 11.9 mm; with less, the numeral's box would set where the text starts.
#2 · Give the chapter heading the page
headings: {
fontFamily: 'Archivo', color: col('band'),
levels: [
// parity: 'odd' keeps openers on rectos, so the numeral's right-edge anchor is the
// fore-edge. The copy is fitted so no chapter spills a few lines onto a page of its own,
// which would leave that page and a blank verso before the next opener.
{ level: 1, span: 'page', breakBefore: { enabled: true, parity: 'odd' },
// 0: the hidden title's default 0.5 em would add a grid line, and AIR alone sets the gap
marginBottom: pt(0), advancedDesign: opener },
{ level: 2, fontSize: pt(11.5), lineHeight: pt(LEAD), numberingTemplate: '{1}.{2}',
marginTop: pt(LEAD), marginBottom: pt(0) }, // one grid line above, none below
],
},
span: 'page' opens each chapter on a new page and sets the level-1 heading across both columns; advancedDesign draws the opener in place of the heading text, and the body starts below the reserved height. breakBefore with parity: 'odd' puts every opener on a recto, where the numeral's right-hand anchor is the fore-edge. At level 2, numberingTemplate: '{1}.{2}' numbers the sections 3.1, 3.2… in the band colour; a level 3 with '{1}.{2}.{3}' would go on to 3.1.1.
#3 · Name the chapter colour once
const palette = {
ink: '#1b1f23', // text: a cool near-black
band: '#c2562b', // the chapter colour: band, tab, section numbers, references, captions
band2: '#2e6f73', // the second chapter colour, a teal; the sea in Figure 3.1
land: '#d5cbc0', // the crust in the drawings
muted: '#6b6259', // running heads and the colophon
paper: '#ffffff', // type on the band
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the link.
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 band, so nothing prints blue.
{ id: 'main-color', name: 'band (defaults)', value: { hex: palette.band, model: 'hex' } },
];
// {style="teal"} on a heading line swaps 'band' up to the next level-1 heading: the style's
// palette reaches design slots through their link and repaints every text colour equal to
// the base 'band'.
const headingStyles = [{ id: 'teal', palette: { band: palette.band2 } }];
Every colour in the configuration links to one of these entries. The engine's own defaults link to main-color, so pointing that entry at the band colour also recolours every default the configuration leaves unset. Chapter 4's heading line, # Fire from \\ Below {style="teal" topic="Volcanoes" lead="…"}, picks the style, which swaps band until the next level-1 heading. Design slots follow the swap through their palette link, and text colours equal to the base band are repainted, so the tab, the section and list numbers, the references, the caption label and the drop folio turn teal on pages 43 and 44. The same line fills {attr.topic} and {attr.lead}, and its \\ breaks {titleText} where the author wants it (heading attributes, line breaks in titles).
#4 · Let the first citation place each figure
const figure = (id, placement, caption) => ({ id, typeId: 'figure', kind: 'svg', createdAt: 0,
updatedAt: 0, svg: { fileId: `${id}.svg`, width: ART[id].width, height: ART[id].height },
placement, caption, altText: ALT[id] }); // altText: read aloud in a PDF or HTML edition
const resources = [
// 'auto' may take the citing page's foot, 'top' never can (gotcha: top-float-next-page)
figure('plate-cycle', { position: 'auto', span: 'page' },
t({ en: 'A plate’s life in cross-section: born at a ridge (left), it cools as it drifts away '
+ 'and sinks under a continent; dots mark earthquakes.',
es: 'La vida de una placa, en corte: nace en la dorsal (izquierda), se enfría al alejarse y '
+ 'se hunde bajo el continente; los puntos son terremotos.' })),
figure('two-volcanoes', { position: 'bottom', span: 'page' }, // under the text on a last page
t({ en: 'Two volcanoes in cross-section: a broad shield built of runny basalt flows (left) '
+ 'and a steep stratovolcano of lava and ash layers (right).',
es: 'Dos volcanes en corte: un escudo ancho, de coladas de basalto fluido (izquierda), y un '
+ 'estratovolcán de capas de lava y ceniza (derecha).' })),
];
A :ref numbers its figure and places it in the first free slot after the paragraph that cites it. Figure 3.1 is auto. It is cited on the opener while both columns still have room, so it takes the foot of that page; as a top float it would have opened page 42, because a float never goes above its own reference. Figure 4.1 is cited low in the second column of page 43, where a page-wide band no longer fits, so bottom sends it to page 44. That is the chapter's last page, and on a last page the engine lifts foot floats to sit directly under the last lines of text, with no gap above them.
#5 · Heads, a thumb tab and a drop folio
const HEAD = 15.5; // mm from the trim to the folio's and the head's baseline: 8.5 above TOP
const INSET = 9; // mm from the folio's edge to the head: room for a three-digit folio
const TAB = { y: 36, w: 9, h: 26 }; // the thumb tab, mm: its top, its width, its height
const tabSize = (w) => ({ width: mm(w), height: mm(TAB.h) });
const baseline = (size) => mm(HEAD - 0.96 * size * PT); // box: 1.2 × size, baseline 0.8 down
const label = { fontFamily: 'Archivo Narrow', fontSize: pt(7.5), fontWeight: 600,
letterSpacing: pt(1.3), textTransform: 'uppercase', color: col('muted') };
const folio = { fontFamily: 'Archivo', fontSize: pt(9), fontWeight: 800, color: col('ink') };
const side = (parity) => { // the fore-edge is a verso's left edge and a recto's right edge
const [edge, s] = parity === 'even' ? ['left', 1] : ['right', -1]; // s: into the page
const at = (to, x, y, size) => ({ anchor: { to, edge: `top-${edge}` },
offset: { x: mm(s * x), y }, ...(size && { size }) });
return [
{ kind: 'text', id: `folio-${parity}`, content: '{pageNumber}', ...folio,
placement: at('page', OUTER, baseline(9)) },
// Textbooks name the chapter on the verso and the section on the recto: {firstMark.h2}
// is the first level-2 heading that starts on the page, or the one in force.
{ kind: 'text', id: `head-${parity}`, content: s > 0 ? '{chapterTitle}' : '{firstMark.h2}',
...label, placement: at('page', OUTER + INSET, baseline(7.5)) },
{ kind: 'box', id: `tab-${parity}`, style: { backgroundColor: col('band') }, // off the trim
placement: at('bleed', 0, mm(BLEED + TAB.y), tabSize(BLEED + TAB.w)) },
{ kind: 'text', id: `tab-no-${parity}`, content: '{chapterNumber}', ...folio, fontSize: pt(13),
color: col('paper'), // design text centres by default: here, on the trimmed tab
placement: at('page', 0, mm(TAB.y), tabSize(TAB.w)) },
].map((element) => ({ ...element, parity, pages: 'body' })); // never on an opener
};
const header = { elements: [...side('even'), ...side('odd')] };
const footer = { elements: [{ kind: 'text', id: 'drop-folio', content: '{pageNumber}',
...folio, color: col('band'), pages: 'opener', // centred by its anchor
placement: { anchor: { to: 'container', edge: 'top' }, offset: { y: mm(10) } } }] };
Each header element hangs from a top corner of the page and is filtered by parity, so the folio and the tab always sit on the fore-edge. The tab's box hangs from the bleed's corner instead and widens with BLEED, so it still bleeds after trimming. pages: 'body' keeps all of these off the openers, which get a drop folio from the footer. The verso names the chapter with {chapterTitle}, on one line, because the \\ only breaks the title in the opener. Textbooks usually name the section on the recto. The recto head prints it with {firstMark.h2}: the first section heading that starts on the page, or the one in force where none does. These four pages never show it, because both of their rectos are openers.
#6 · Start the book at chapter 3
const continuation = { pageNumbering: { startAt: 41 }, // an odd folio: page 1 is still a recto
headings: { h1: 2, h2: 0, h3: 0, h4: 0, h5: 0, h6: 0 } }; // the next # is chapter 3
const doc = await buildDocumentWithFonts({ markdown, resources, continuation }, config(),
kitFonts(FONTS));
showPages(doc, { title: t({ en: 'Chapter opener on a full-bleed band',
es: 'Apertura de capítulo sobre banda a sangre' }) });
These pages are chapters 3 and 4 of a longer book, so buildDocument gets a continuation with the counters as chapters 1 and 2 left them. With h1: 2 in its headings, the next # is chapter 3: {chapterNumber} prints 3, sections number from 3.1 and the first figure becomes 3.1. pageNumbering.startAt: 41 starts the folios at 41. The first page stays a recto whatever its folio, because parity is counted on the physical page and pageIndexOffset is left at 0; the first folio, 41, is odd to match.
The whole recipe
// ═══ Postext Cookbook · Nº 003 · Chapter opener on a full-bleed band ══════════════
// https://postext.dev/en/cookbook/chapter-opener-bleed-band
// Code: MIT · Text: original (CC BY 4.0) · Drawings: generated in code (CC BY 4.0)
// Fonts: Roboto Serif, Archivo, Archivo Narrow (SIL OFL 1.1) · Needs postext ≥ 1.57.0
// Two chapters of a geology textbook. Every level-1 heading becomes a colour band bled off the
// top of the page, its number standing on the band's foot; a heading style recolours chapter 4.
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'chapter-opener-bleed-band';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: semantic colours, and the style that swaps a chapter's
const palette = {
ink: '#1b1f23', // text: a cool near-black
band: '#c2562b', // the chapter colour: band, tab, section numbers, references, captions
band2: '#2e6f73', // the second chapter colour, a teal; the sea in Figure 3.1
land: '#d5cbc0', // the crust in the drawings
muted: '#6b6259', // running heads and the colophon
paper: '#ffffff', // type on the band
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the link.
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 band, so nothing prints blue.
{ id: 'main-color', name: 'band (defaults)', value: { hex: palette.band, model: 'hex' } },
];
// {style="teal"} on a heading line swaps 'band' up to the next level-1 heading: the style's
// palette reaches design slots through their link and repaints every text colour equal to
// the base 'band'.
const headingStyles = [{ id: 'teal', palette: { band: palette.band2 } }];
// #endregion
// #region answer: the opener: a bleed band, the numeral on its foot, texts from the heading
const TOP = 24; // top margin, mm: the opener's container starts here
const OUTER = 16; // outer margin, mm: the numeral and the folios line up on it
const BLEED = 0; // mm: 0 on screen; about 3 for print, which also switches on page.cutLines
const BAND = 100; // mm from the trim to the foot of the band
const NUMERAL = 168; // pt; the baseline of a design text sits 0.8 down its line box
const PT = 25.4 / 72; // mm in a point
const AIR = 12; // mm, foot to text: ≥ 0.2 × NUMERAL × PT ≈ 11.9, the numeral box below its baseline
const BEARING = 2; // mm past the text edge: a rough optical nudge, as each digit's bearing differs
const bleedTop = { to: 'bleed', edge: 'top-left' }; // the trim's corner, pushed out by BLEED
// Design text centres by default; in a heading design it wraps by default too.
const onBand = { color: col('paper'), align: 'left' };
The composed script.js runs as it is: paste it into any page’s module script, or open the recipe on CodePen. Recipe folder on GitHub ↗ (opens in a new tab)
Variations
#Make the band deeper
BAND sets the depth of the band, the numeral's position and the height reserved above the text. A deeper band pushes text onto the next page, so refit each chapter (see the last pitfall) or let chapters run on.
-const BAND = 100; // mm from the trim to the foot of the band
+const BAND = 128; // mm from the trim to the foot of the band#Print it with a bleed
With a 3 mm bleed, the band, its foot and the tab run 3 mm past the trim, the numeral stays on the foot, and page.cutLines switches on with the same value.
-const BLEED = 0; // mm: 0 on screen; about 3 for print, which also switches on page.cutLines
+const BLEED = 3; // mm: 0 on screen; about 3 for print, which also switches on page.cutLines#Add a colour for another chapter
Each chapter colour is one more palette entry and one more style; write {style="slate"} on that chapter's heading line.
band2: '#2e6f73', // the second chapter colour, a teal; the sea in Figure 3.1
+ band3: '#3d4f6b', // a third chapter colour, a slate blue
@@
-const headingStyles = [{ id: 'teal', palette: { band: palette.band2 } }];
+const headingStyles = [{ id: 'teal', palette: { band: palette.band2 } },
+ { id: 'slate', palette: { band: palette.band3 } }];#Let chapters run on
With 'any' a chapter opens on the next page. After a chapter that ends on a recto it opens on the verso, with no blank page before it, and its numeral stands by the spine, since it hangs from the page's right edge. These pages stay the same, as chapter 3 already ends on a verso.
- { level: 1, span: 'page', breakBefore: { enabled: true, parity: 'odd' },
+ { level: 1, span: 'page', breakBefore: { enabled: true, parity: 'any' },Pitfalls
Pitfall
An opener reserves height down to its lowest page-anchored element
An advanced-design opener reserves the height of its lowest element, and page- or bleed-anchored elements below the heading count too, so decoration at the foot of the page pushes the text to the next page. Give such an element reserve: false (since postext 1.5): it is painted where it is anchored and reserves nothing. Elements that follow the band itself (anchored to its foot, or 'fill' tall) never set its height. Designed openers →
Pitfall
Attribute values: no { or }; single-quote a value with "
An attribute value ends at the closing brace, so it cannot hold { or }. A value that contains a double quote goes in single quotes; a dollar sign is fine. Heading attributes →
Pitfall
A 'top' float goes to the page after its citation unless it may head the citing page
By default a float never goes above its own reference, so a page-wide 'top' float cited on page N opens page N+1. Set placement.citingPage: true on the resource or its type's defaultPlacement (or layout.floatsAtCitingPage for the whole book, since postext 1.25) and it heads page N instead, the text above the reference moving down under it, when it fits within layout.maxTopFraction and the citing line stays on that page. It never heads a chapter's first page or a page after a forced break: there it still opens the next page, and 'auto' or 'bottom' can take the foot of the citing page. Figure placement →
- The band has a fixed height, while the kicker, the title and the standfirst hang from the top margin and grow downwards, so a longer standfirst or a three-line title runs into the foot. Keep standfirsts to about five lines, as both editions do, or derive
BANDfrom the longest opener. - The formula for the numeral's
yassumeslineHeight: 1. A design text's baseline sits 0.8 of the way down its line box, and0.8 * NUMERALis that distance only when the box is as tall as the type. Change the line height or the anchor and the formula has to change with it.BEARINGis set by eye, because each digit has its own side bearing (here the 3 and the 4 end 0.8 mm apart). - A style's palette recolours design elements and text. A picture keeps the colours it was drawn with: Figure 4.1 is teal because the code draws it from
band2, and a terracotta figure placed in chapter 4 would stay terracotta. - With
parity: 'odd', a chapter that runs a few lines past its last page leaves a nearly empty page and a blank verso before the next opener. Fit the copy, as both editions here do, and check each chapter's last page whenever the text orBANDchanges.
Credits
- Recipe
- Ignacio Ferro
- Text
- Original prose, CC BY 4.0
- Fonts
- Roboto Serif (SIL OFL 1.1) · Archivo (SIL OFL 1.1) · Archivo Narrow (SIL OFL 1.1)
Edit this write-up ↗ (opens in a new tab)Recipe folder on GitHub ↗ (opens in a new tab)


