Skip to main content
Recipe number 47

Cookbook · Chapter 4 · Running heads & folios

Walking guide with thumb tabs

A pocket guide with one heading style per walk, whose palette recolours the fore-edge tab, the stop numbers, the box’s tint and the blank verso before the walk.

pp. 6–7 of 7

  • Trim 120 × 200 mm
  • 1 column
  • Albert Sans 9.4/13.2
  • Asap Condensed
  • DM Serif Display
  • 7 pages
  • Level
  • Postext 1.57.1
  • Laid out in 56 ms
  • 245 lines of code

In short

A pocket guide to walks around Lisbon. Each walk has its own colour, shown in a tab on the page edge so you can find it with your thumb.

What you'll build

The first seven pages of Lisbon on Foot, a pocket guide of 120 × 200 mm. The cover is a wall of blue-and-white azulejos with the title on a panel framed like a Lisbon street sign, and page 2 introduces the three walks with a map of their routes. Each walk has a colour, terracotta for Alfama and yellow for the Baixa, and a thumb tab on the fore-edge shows that colour and the walk’s number at the same height on every page of the walk. The opener band, the numbered stops, the recto running head and the tint of the Don’t miss box change with it. The blank verso that sends Walk 2 to a recto is painted in Walk 2’s yellow and prints its numeral. The text is Albert Sans, set ragged; the names are DM Serif Display and the labels Asap Condensed.

This recipe answers

  • How do I hide running heads on openers and blank pages, or paint a blank verso in the part colour?
  • How do I set running heads: book title on the left page, chapter title on the right, page number outside?
  • How do I add a numbered tab ("BOX 1-1"), a corner icon, or a margin icon with a rule?
  • How do I add colour-key swatches to text, captions or table notes?

The short answer

script.js · lines 60–81in full code
// '# Alfama {style="alfama"}' opens a section that runs to the next level-1 heading. Its
// palette gives band, bandInk, onBand and wash the walk's values on the section's pages,
// in the page furniture and in the text alike.
const walkStyles = Object.keys(WALKS).map((id) => ({ id, palette: WALKS[id] }));
// The tab has one size and one place on every page, hanging from the foot of the opener
// band; only its colour and its number change from walk to walk.
const TAB = { y: BAND, width: 7, height: 24 }; // mm
const tab = (parity, edge) => text(`tab-${parity}`, '{chapterNumber}', {
  ...label, fontSize: pt(11), fontWeight: 700, color: col('onBand'), align: 'center',
  verticalAlign: 'middle', overflow: 'clip', box: { backgroundColor: col('band') },
  parity, pages: 'all', // the walk's first page is an 'opener' page: the tab goes there too
}, { ...at('bleed', edge, 0, TAB.y), ...size(mm(TAB.width), mm(TAB.height)) });
const tabs = [tab('odd', 'top-right'), tab('even', 'top-left')]; // on the fore-edge
// The blank verso that pushes a walk onto a recto belongs to that walk (gotcha:
// section-last-wins), so the field takes the next walk's colour and its numeral the number.
const blankPage = [
  box('field', { backgroundColor: col('band') },
    { ...at('bleed', 'top-left', 0, 0), ...size('fill', 'fill') }),
  tileImage('field-tiles', 'tiles-page', 'top-left', 'fill', 'auto'),
  text('field-number', '{chapterNumber}', { ...display, fontSize: pt(220), lineHeight: 1,
    color: col('onBand'), overflow: 'clip' }, at('page', 'bottom-left', MARGIN.outer, -24)),
].map((el) => ({ ...el, pages: 'blank' }));

One tab and one blank-page field, coloured by the walk they belong to

Ingredients

Type
Albert Sans, DM Serif Display, Asap Condensed (SIL OFL 1.1)
Assets
  • The tiles, the map of the routes and its pins, drawn in code (Ignacio Ferro, CC BY 4.0)

Method

#1 · Name the colours a walk changes

script.js · lines 16–40in full code
const palette = {
  ink: '#1b2430', // text: a blue-black
  paper: '#fffdf8', // the page
  band: '#1f4e9c', // the section colour: tile blue until a walk replaces it
  bandInk: '#1d4a94', // the section colour for type on paper
  onBand: '#ffffff', // type set on the band
  wash: '#e8eef8', // the section's box tint
  muted: '#5e6875', // running heads, notes, chip outlines
};
// Each walk's values for those four. Baixa yellow is too light for white type, so its
// onBand is the ink. The text is recoloured by value, so the four base values must differ.
const WALKS = {
  alfama: { band: '#b9533a', bandInk: '#a1432b', onBand: '#ffffff', wash: '#f7e7e0' },
  baixa: { band: '#e2b23d', bandInk: '#7d5a0f', onBand: '#1b2430', wash: '#fbf0d5' },
  belem: { band: '#2b7a78', bandInk: '#236866', onBand: '#ffffff', wash: '#e1eeed' },
};
const NAMES = { alfama: 'Alfama', baixa: 'Baixa', belem: 'Belém' };
// A walk's palette follows the paletteId; the hex beside it is the colour's base value.
const col = (id) => ({ hex: palette[id] ?? WALKS[id].band, model: 'hex', paletteId: id });
const entry = (id, hex) => ({ id, name: id, value: { hex, model: 'hex' } });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => entry(id, hex)),
  ...Object.entries(WALKS).map(([id, w]) => entry(id, w.band)), // for :swatch{color="alfama"}
  entry('main-color', palette.ink), // the engine's defaults link here: nothing prints blue
];

A heading style’s palette replaces entries by id on the pages of its section (heading styles), so every colour that should follow the walk links to one of four entries: band for the fields, the tab and the stop circles, bandInk for type on paper, onBand for type on a field and wash for the box. White on the Baixa yellow measures 2:1, so that walk’s onBand is the ink, at 8:1. Design elements follow the id, while the text is recoloured by value: a colour equal to an entry’s base hex takes the walk’s value, which is why the four base values all differ. The box title on page 4 and the line that sends you on to Walk 2 on page 5 are text in bandInk, and both print in terracotta.

#2 · Keep the running heads to body pages

script.js · lines 85–107in full code
const head = (id, content, parity, placement, style = {}) => ({ ...text(id, content, {
  ...label, fontSize: pt(7.8), letterSpacing: pt(1.3), color: col('muted'), overflow: 'clip',
  ...style }, placement), parity, pages: 'body' }); // never on openers or blank pages
const folio = { fontSize: pt(8.5), fontWeight: 700, color: col('ink') };
// Anchored to the page: from its top-right corner a negative x runs inwards
// (gotcha: negative-offsets).
const heads = [
  head('verso-folio', '{pageNumber}', 'even', at('page', 'top-left', MARGIN.outer, HEAD.y), folio),
  head('verso-title', '{title}', 'even', at('page', 'top-left', MARGIN.outer + HEAD.gap, HEAD.y)),
  head('recto-title', `${t({ en: 'Walk', es: 'Paseo' })} {chapterNumber} · {chapterTitle}`, 'odd',
    at('page', 'top-right', -(MARGIN.outer + HEAD.gap), HEAD.y), { color: col('bandInk') }),
  head('recto-folio', '{pageNumber}', 'odd', at('page', 'top-right', -MARGIN.outer, HEAD.y), folio),
];
// Array order is paint order: the blank page's field comes last and covers the tab there.
const header = { elements: [...heads, ...tabs, ...blankPage] };
// A walk's first page has no running head: its folio drops to the foot.
const footer = { elements: [{ ...head('drop-folio', '{pageNumber}', 'all',
  at('container', 'top', 0, 7), folio), pages: 'opener', align: 'center' }] };
// Page 2 comes before Walk 1, where {chapterNumber} is empty, so its header has no tabs. With
// the level's break off (gotcha: style-inherits-break), it is a 'body' page.
const introStyle = { id: 'intro', numbered: false, header: { elements: heads },
  breakBefore: { enabled: false }, advancedDesign: { enabled: false },
  fontSize: pt(24), lineHeight: pt(2 * LEAD), marginBottom: pt(LEAD / 2) };

After layout every page gets a role (text elements). A walk’s first page is an opener, because its heading breaks the page; the padding page before a recto is blank; the rest are body. The heads take pages: 'body', so the openers on pages 3 and 7 and the blank page 6 have none, and the drop folio takes 'opener'. The verso prints the frontmatter’s {title}, the recto Walk {chapterNumber} · {chapterTitle} in bandInk, terracotta on page 5. The tabs from the short answer take 'all'. The blank page’s field comes after them in the array, and since array order is paint order it covers the tab on page 6. Page 2, the introduction, comes before Walk 1, so {chapterNumber} is empty there, and its style has a header of its own with the four heads and no tabs. Without it, page 2 would print an empty blue tab.

#3 · Open each walk under its band, and number its stops

script.js · lines 111–138in full code
const walkLevel = { level: 1, breakBefore: { enabled: true, parity: 'odd' }, // a recto
  // The band ends 30 mm into the text area; a floor of 8 grid lines, with nothing added
  // under it, starts the text 7.3 mm below the band.
  marginBottom: pt(0), advancedDesign: { enabled: true, minHeight: pt(8 * LEAD), slot: {
    elements: [
      box('band', { backgroundColor: col('band') },
        { ...at('bleed', 'top-left', 0, 0), ...size('fill', mm(BAND)) }),
      tileImage('tiles', 'tiles-band', 'top-right', 'auto', mm(BAND)),
      text('kicker', `${t({ en: 'Walk', es: 'Paseo' })} {chapterNumber}`, { ...label,
        fontSize: pt(9), letterSpacing: pt(2), color: col('onBand') },
      at('page', 'top-left', MARGIN.inner, 17)), // walks open on rectos: inner is left
      text('title', '{titleText}', { ...display, fontSize: pt(34), lineHeight: 1,
        color: col('onBand') }, { ...at('#kicker', 'below', 0, 1), ...size(mm(70), 'auto') }),
      text('route', '{attr.route}', { fontFamily: 'Albert Sans', italic: true, fontSize: pt(10),
        color: col('onBand') }, { ...at('#title', 'below', 0, 1.5), ...size(mm(70), 'auto') }),
    ] } } };
const STOP = 5.4; // mm: the diameter of a stop's circle
const stopLevel = { level: 3, numberingTemplate: '{3}', // restarts at every walk
  // A grid line above a stop and no margin under it, so the circle can sit 3.2 mm down its
  // two grid lines: about 8.3 mm of white above a stop and 2.1 under it, 6.4 between paragraphs.
  marginTop: pt(LEAD), marginBottom: pt(0), advancedDesign: { enabled: true, slot: { elements: [
    text('number', '{number}', { ...label, fontSize: pt(9), fontWeight: 700, align: 'center',
      verticalAlign: 'middle', color: col('onBand'), overflow: 'clip',
      box: { backgroundColor: col('band'), borderRadius: mm(STOP / 2) } },
    { ...at('container', 'top-left', 0, 3.2), ...size(mm(STOP), mm(STOP)) }),
    text('name', '{titleText}', { ...display, fontSize: pt(13.5), lineHeight: 1.1,
      color: col('ink') }, { ...at('#number', 'right-of', 2.4, 0.2), ...size('fill', 'auto') }),
  ] } } };

The band is anchored to the bleed, which is the trim here, and reaches 30 mm into the text area. The design ends with the band and minHeight reserves eight grid lines, 37.3 mm; the opener takes the larger depth, so on pages 3 and 7 the text starts 7.3 mm under the band. Each stop is a level-3 heading whose design sets {number} in a 5.4 mm circle filled with band. The template {3} restarts at every walk, since a level-1 heading resets the deeper counters, and the pins on the map carry the same numbers. A stop has a grid line of margin above it and none below, and its circle sits 3.2 mm down the two grid lines the heading fills. That leaves about 8.3 mm of white above the circle and 2.1 mm under it; paragraphs are 6.4 mm apart.

#4 · Hang a tile on the box, and keep the chips in ink

script.js · lines 166–181in full code
const calloutStyles = [{ id: 'dontmiss', title: t({ en: 'Don’t miss', es: 'No te lo pierdas' }),
  background: col('wash'), // one device: the walk's tint
  // The tile hangs half off the box's outer side, flush with its top: the left side on a verso.
  // With 6.5 mm of padding on both sides the title stays in line with the box's text there too.
  // The tile's colours are drawn into the SVG, so it stays tile blue in every walk.
  padding: { top: mm(3.4), right: mm(6.5), bottom: mm(3.4), left: mm(6.5) },
  icon: { kind: 'resource', resourceId: 'tile', size: mm(10), position: 'corner',
    cornerSide: 'outer' },
  titleStyle: { ...label, fontSize: pt(8.5), fontWeight: 700, letterSpacing: pt(1.5),
    color: col('bandInk') },
  body: { fontSize: pt(9), lineHeight: pt(12.4), color: col('ink') } }];
// The facts are ink on paper in every walk: the walk's colour is kept for the tab, the stops
// and the box, and a chip linked to 'band' would follow it too.
const chipStyles = [{ id: 'fact', background: col('paper'), borderColor: col('muted'),
  borderWidth: pt(0.6), borderRadius: mm(0.8), paddingX: mm(1.4), paddingY: mm(0.5),
  fontFamily: 'Asap Condensed', fontSize: em(0.92), color: col('ink'), bold: true }];

The box has no rule or border, only the walk’s tint and a tile drawn in code on its corner (callout styles). cornerSide: 'outer' hangs the tile half off the box’s outer side, flush with its top; on page 4, a verso, that is the left side, where the title starts. With 6.5 mm of padding on both sides the title clears the tile and stays in line with the box’s text on either page. The walk’s palette recolours the tint and the title, while the tile stays blue, because its colours are drawn into the SVG. A chip linked to band would take the walk’s colour as well; here the facts stay out of it, so the chips are ink on paper with a grey outline in muted, the same in every walk.

#5 · Key the map with the walks’ swatches

script.js · lines 529–543in full code
const map = svg('routes', MAP.width, MAP.height, { placement: { position: 'here' }, ...t({ en: {
  caption: 'The three walks. The numbered pins are the stops in the text.',
  note: ':swatch{color="alfama"} Walk 1, Alfama · :swatch{color="baixa"} Walk 2, Baixa · '
    + ':swatch{color="belem"} Walk 3, Belém, 6 km west (inset)',
  altText: 'Map of central Lisbon north of the river: the yellow route runs from the '
    + 'waterfront up the Baixa grid to Rossio; the terracotta route climbs east from the '
    + 'cathedral through Alfama. An inset shows the teal Belém route.',
}, es: {
  caption: 'Los tres paseos. Los pines numerados son las paradas del texto.',
  note: ':swatch{color="alfama"} Paseo 1, Alfama · :swatch{color="baixa"} Paseo 2, Baixa · '
    + ':swatch{color="belem"} Paseo 3, Belém, 6 km al oeste (en el detalle)',
  altText: 'Plano del centro de Lisboa al norte del río: la ruta amarilla sube desde el '
    + 'muelle por la cuadrícula de la Baixa hasta el Rossio; la terracota sube hacia el este '
    + 'desde la catedral por Alfama. En un detalle, la ruta verde azulada de Belém.',
} }) });

The map is an SVG resource set where ::resource{id="routes"} stands, with a resource type of its own so that its caption reads Map 1. The note keys the routes with three swatches, :swatch{color="alfama"} and the same for baixa and belem. A swatch takes the id of a palette entry (inline formatting). The palette gets one entry per walk from WALKS, and the drawing takes its route colours from the same object, so the key matches the routes and the tabs. The numbers in the pins are drawn as strokes, so the map carries no font.

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 047 · Walking guide with thumb tabs ═══════════════════
// https://postext.dev/en/cookbook/walking-guide-thumb-tabs
// Code: MIT · Text: original (CC BY 4.0) · Map and tiles: drawn in code (CC BY 4.0)
// Fonts: Albert Sans, DM Serif Display, Asap Condensed (SIL OFL 1.1) · Needs postext ≥ 1.34.0
// A pocket guide to Lisbon. Each walk is a heading style that sets four colours, and the tab,
// the stop numbers, the box's tint and title and the blank page before the walk take them.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'walking-guide-thumb-tabs';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: 'band' and three partners are the entries a walk overrides
const palette = {
  ink: '#1b2430', // text: a blue-black
  paper: '#fffdf8', // the page
  band: '#1f4e9c', // the section colour: tile blue until a walk replaces it
  bandInk: '#1d4a94', // the section colour for type on paper
  onBand: '#ffffff', // type set on the band
  wash: '#e8eef8', // the section's box tint
  muted: '#5e6875', // running heads, notes, chip outlines
};
// Each walk's values for those four. Baixa yellow is too light for white type, so its
// onBand is the ink. The text is recoloured by value, so the four base values must differ.
const WALKS = {
  alfama: { band: '#b9533a', bandInk: '#a1432b', onBand: '#ffffff', wash: '#f7e7e0' },
  baixa: { band: '#e2b23d', bandInk: '#7d5a0f', onBand: '#1b2430', wash: '#fbf0d5' },
  belem: { band: '#2b7a78', bandInk: '#236866', onBand: '#ffffff', wash: '#e1eeed' },
};
const NAMES = { alfama: 'Alfama', baixa: 'Baixa', belem: 'Belém' };
// A walk's palette follows the paletteId; the hex beside it is the colour's base value.
const col = (id) => ({ hex: palette[id] ?? WALKS[id].band, model: 'hex', paletteId: id });
const entry = (id, hex) => ({ id, name: id, value: { hex, model: 'hex' } });
const colorPalette = [
  ...Object.entries(palette).map(([id, hex]) => entry(id, hex)),
  ...Object.entries(WALKS).map(([id, w]) => entry(id, w.band)), // for :swatch{color="alfama"}
  entry('main-color', palette.ink), // the engine's defaults link here: nothing prints blue
];
// #endregion
const TRIM = { width: 120, height: 200 }; // a pocket guide
// Mirrored, and tighter than a book's at top and foot: a pocket guide keeps 164 mm of text.
const MARGIN = { top: 18, bottom: 18, inner: 14, outer: 16 };
const MEASURE = TRIM.width - MARGIN.inner - MARGIN.outer; // 90 mm, about 55 characters
const LEAD = 13.2; // body leading in pt: the baseline grid
const BAND = 48; // mm: a walk opener's colour band, from the top edge
const HEAD = { y: 10, gap: 7 }; // running heads from the top edge; folio to title (mm)

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

#Leave the blank verso unpainted

Without the field, page 6 keeps its tab: pages: 'all' prints it on the blank page too, in Walk 2’s yellow with a 2.

-const header = { elements: [...heads, ...tabs, ...blankPage] };
+const header = { elements: [...heads, ...tabs] };

#Add the third walk

WALKS already holds Belém’s colours and walkStyles its style, so the walk needs only its heading in the content. The walk opens on page 9, after a blank page 8 painted teal with a white 3.

+# Belém {style="belem" route="From the monastery to the tower"}
+
+Tram 15 runs from Praça da Figueira to Belém along the river.

Pitfalls

Pitfall

A page takes the header of the last section that starts on it

When two heading styles start on one page, the page takes the header, footer and palette of the last one. A separator blank belongs to the chapter before it, parity padding to the chapter after it. Running heads per section →

Pitfall

A heading style inherits its level's page break

A headingStyles entry takes every field it leaves out from its heading level, breakBefore included. A contents page or a colophon styled on an H1 after a :::pagebreak inherits parity 'odd' and lands behind a blank page. Give such a style breakBefore: { enabled: false }. Heading styles →

Pitfall

Container-relative negative offsets render nothing

Auto-width design text is clamped to its container, so a negative offset from the container pushes it out and nothing renders. Anchor such elements to the page or the bleed with explicit mm offsets, or give them a fixed width. Anchoring design elements →

Pitfall

Page 1 is a recto: plan pages with physical numbers

Page 1 is a right-hand page and page 2 the first verso, so plan spreads with physical page numbers: an opener on an even page faces the odd page after it. Page and column breaks →

  • Page 6 exists because Walk 1 ends on page 5, a recto. A walk that ends on a verso leaves no blank page, and the next walk’s colour then shows only on its own pages.
  • Before the first numbered walk, {chapterNumber} is empty, so an element that prints it, such as the tab, needs a style there that leaves it out.

Credits

Text
Original prose, CC BY 4.0
Images
  • The tiles, the map of the routes and its pins, drawn in code · Ignacio Ferro · CC BY 4.0
Fonts
Albert Sans (SIL OFL 1.1) · DM Serif Display (SIL OFL 1.1) · Asap Condensed (SIL OFL 1.1)
Sandbox