Skip to main content
Recipe number 52

Cookbook · Chapter 8 · Tables

Bistro menu: prices on a tab stop

A two-sided bistro menu: prices set flush right on a tab stop, wines in a borderless table, and a brass rule anchored to either side of each course head.

  • Trim 230 × 310 mm
  • 1 column
  • Noticia Text 10.5/14.5
  • Josefin Sans
  • Limelight
  • 2 pages
  • Level
  • Postext 1.57.1
  • Laid out in 47 ms
  • 154 lines of code

In short

A two-sided menu for a made-up Paris restaurant. It shows how to push each price to the right edge with a tab, and how to set a wine list in a table with no visible lines.

What you'll build

The autumn card of Les Tanneurs, an imaginary Paris bistro: one sheet, 230 × 310 mm, printed on both sides. On the front, a striped awning hangs over the name, set in Limelight. Each course head stands between two brass rules that run out to the margins, with four dishes below it. A dish is its French name in bold with the garnish, an English line in italic beneath it and the price in bold, flush right. A dark green V disc marks the vegetarian dishes and an outlined SG pill the gluten-free ones. Each dish is one paragraph, and a tab sends its price to a stop at the right margin. On the back, the wine list sits under a shelf of bottles, with the glass and bottle prices in columns headed 12 cl and 75 cl, in a table with no rules and no caption.

This recipe answers

  • How do I make a table with header rows, merged cells, column widths and per-cell alignment?
  • How do I make inline chips: keyboard keys, tags, word banks for exercises?
  • How do I set unnumbered artwork: ornaments, vignettes, logos?
  • How do I add images and tables from code (resources) instead of Markdown ![]()?

The short answer

script.js · lines 28–42in full code
// Each course is a :::paragraphs group in the dish style. Its one tab stop stands at the end of
// the measure and ends there the text after the tab, so `:tab **7**` sets the price flush right
// however long the dish is. A backslash at the end of the line breaks it: the dish and its
// translation are one paragraph, and the price shares the dish's first line.
const dish = { id: 'dish', name: 'Dish', textAlign: 'left', // the card is centred; a dish is not
  tabStops: [{ position: 'end', align: 'end' }],
  spaceBetween: pt(LEAD / 2), // half a line between two dishes: each dish 2½ lines of LEAD
  marginTop: pt(LEAD), // a line of air under the course head
  indent: pt(LEAD / 4), endIndent: pt(LEAD / 4) }; // in line with the wine list's cell text
// The wine list stays a table: its prices stand in two columns under the heads 12 cl and 75 cl.
// The document's tableStyle turns off every rule and fill (#region wines).
const tableStyle = { rules: 'none', cellPadding: pt(LEAD / 4), // a row: 1½ lines of LEAD
  bodyFontFamily: TEXT, bodyFontSize: pt(BODY), bodyColor: col('ink'),
  headerFontFamily: LABEL, headerFontSize: pt(8.5), headerColor: col('wine'),
  headerBackgroundEnabled: false }; // header cells: the wine list's labels

Dish on the left, price flush right: a tab stop at the end of the measure

Ingredients

Type
Limelight, Noticia Text, Josefin Sans (SIL OFL 1.1)
Assets
  • The awning and the shelf of bottles, drawn in code in the page's palette (Ignacio Ferro, CC BY 4.0)

Method

#1 · A tab stop where the price goes

The code is in the short answer above. Each course is a :::paragraphs{style="dish"} group, one paragraph to a dish (Paragraph styles). The dish style has one tab stop, at 'end', the end of the measure, with align: 'end': the text after a tab ends on the stop. So :tab **7** after the garnish and the badges sends the price flush right, however long the dish (Tabs and tab stops). :tab takes the spaces around it, and the backslash at the end of the line is a forced line break, so the English line in italics starts a second line of the same paragraph and the price stays on the first. spaceBetween puts half a line between two dishes, so each dish takes two and a half lines of the 14.5 pt leading. indent and endIndent of a quarter line keep the dishes in line with the text of the wine list's cells on the back. A tabbed paragraph is set line by line; here every line is set ragged anyway.

#2 · One resource type, in place and never numbered

script.js · lines 46–53in full code
// No caption prefix and no caption, so no 'Table 1' line prints under the wine list. Placement
// 'here' sets each piece at its ::resource line; a list that outgrows the page is cut
// between rows and goes on at the head of the next one.
const resourceTypes = [{ id: 'menu', name: 'Menu', shortLabel: 'Menu', captionPrefix: '',
  numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal',
  defaultPlacement: { position: 'here' } }];
const piece = (id, kind, body) => ({ id, typeId: 'menu', kind, createdAt: 0, updatedAt: 0,
  ...body });

The built-in figure and table types print a caption line and float each resource to the first free slot after its first reference. The menu type has no caption prefix and its pieces have no caption, so nothing prints under the drawings or the wine list. Give it captionPrefix: 'Menu' and a numbered line prints under every piece, starting with “Menu 1.” under the awning, which takes the card to four pages. defaultPlacement sets the wine list and each drawing at its ::resource line (Block embed). Without it the wine list floats to the foot of the back, under Le Comptoir and the colophon. The awning and the bottles are SVG resources of the same type, drawn in code and registered with the kit's loadSvg.

#3 · Merge the region rows

script.js · lines 57–70in full code
function wineList(tsv) {
  let m = { ...parseTSV(tsv, { headerRows: 1 }), columnWidths: [5, 1, 1] }; // the head row
  m.rows = m.rows.map((row, r) => row.map((cell, c) => (c === 0 ? cell : { ...cell, align: 'right',
    content: r > 0 && cell.content ? `**${cell.content}**` : cell.content }))); // as the dishes'
  m.rows.forEach(([first, ...rest], r) => { // a line with one field names a region
    if (r === 0 || !first.content || rest.some((cell) => cell.content)) return;
    // One cell across the table, centred on the card like the course heads; a label centred
    // in the first column alone would sit 22.6 mm left of them. The label face is the header's.
    m.rows[r][0] = { ...first, isHeader: true, align: 'center' };
    // mergeCells marks the two cells it covers hiddenBy (gotcha: merged-cells-hiddenby).
    m = mergeCells(m, { start: { row: r, col: 0 }, end: { row: r, col: 2 } });
  });
  return piece('wines', 'table', { table: { model: m } });
}

The wine list stays a table: its two prices stand in columns under their heads, 12 cl and 75 cl, which a row of tab stops would leave without a head. parseTSV(tsv, { headerRows: 1 }) reads the first line as the head row, so Appellation · cépage, 12 cl and 75 cl print over their columns in the header face, Josefin Sans. A line with a single field names a region. Its cell becomes a centred header cell, and mergeCells spreads it across the three columns and marks the two cells it covers hiddenBy (Building table models). Centred in the first column alone, BLANCS would stand 22.6 mm left of the axis that La Cave and Le Comptoir are centred on. A blank line in the TSV becomes a row of empty cells, one and a half lines tall, and that row is the gap above Blancs and Rouges.

#4 · Hang a rule on each side of the course title

script.js · lines 74–88in full code
// The title has no width, so it shrink-wraps its text, and 'top' centres it on the column. Each
// rule hangs off one edge of the title ('left-of', 'right-of'), 4 mm away, and 'fill' runs it
// to the column's edge: 66.7 mm beside PLATS, 56.2 mm beside the longer LE COMPTOIR.
const rule = (edge, x) => ({ kind: 'rule', id: `rule-${edge}`, color: col('brass'),
  thickness: pt(0.75), // heavier than the default 0.5 pt hairline
  placement: { anchor: { to: '#title', edge },
    size: { width: 'fill' }, // to the column's edge
    offset: { x: mm(x), y: pt(6) } } }); // 6 pt down: the middle of Limelight's capitals
const courseHead = { enabled: true, slot: { elements: [
  { kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY, fontSize: pt(15),
    lineHeight: 0.96, // 14.4 pt: the title stays inside one 14.5 pt grid line
    textTransform: 'uppercase', color: col('wine'),
    placement: { anchor: { to: 'container', edge: 'top' } } },
  rule('left-of', -4), rule('right-of', 4),
] } };

A course head is a design in the column. The {titleText} element has no width, so its box is as wide as its capitals, and the 'top' anchor centres it on the column. Each rule hangs off one edge of the title with 'left-of' or 'right-of' and fills to the column's edge (Element placement), so the rules beside PLATS are 66.7 mm long and those beside LE COMPTOIR 56.2 mm, each 4 mm from the letters. The title's lineHeight is a multiple, 0.96, which makes its box 14.4 pt and keeps it inside one 14.5 pt grid line. At 1 the box is 15 pt, each head takes two lines and the card runs to four pages.

#5 · Badges as chips, small print as paragraph styles

script.js · lines 92–110in full code
// A chip is a box around inline text: the V disc is filled, the SG pill only outlined. A chip
// takes the weight of the text around it, so without bold the V is set in 400, a weight not loaded.
const badge = { fontFamily: LABEL, fontSize: pt(7.5), bold: true, // Josefin Sans 700
  borderRadius: pt(8), paddingY: em(0.1), gap: em(0.6) }; // radius clamped to a half-height
const chipStyles = [
  // V: paddingX makes the box as wide as it is tall, a disc. borderWidth 0 removes the default
  // outline, 0.5 pt of main-color, which would ring the green in wine red.
  { id: 'veg', name: 'Vegetarian', ...badge, paddingX: em(0.3), borderWidth: pt(0),
    background: col('bottle'), color: col('paper') },
  { id: 'gf', name: 'Gluten-free', ...badge, paddingX: em(0.45), backgroundEnabled: false,
    borderColor: col('bottle'), borderWidth: pt(0.6), color: col('bottle') },
];
// The notes under the desserts and the colophon on the back: smaller, on the card's axis, a
// line of air above each.
const paragraphStyles = [dish,
  { id: 'notes', name: 'Notes', fontSize: pt(9), marginTop: pt(LEAD) },
  { id: 'colophon', name: 'Colophon', fontSize: pt(7.5), color: col('muted'),
    marginTop: pt(LEAD) },
];

A chip draws a box round a run of text inside the line (Chip styles), so :chip[V]{style="veg"} typed after the garnish puts the disc on the dish's French line, before the tab. The chip styles set bold: true because a chip takes the weight of the text around it, 400 after a garnish, and FONTS loads Josefin Sans in 700 only. The notes under the desserts and the colophon on the back are :::paragraphs blocks at 9 and 7.5 pt, and both styles carry a marginTop of one line (Paragraph styles). Without that margin the notes start on the line after the cheese plate's English line, as if they belonged to the dish.

#6 · Centre the card on one axis

script.js · lines 114–126in full code
// bodyText (in config) centres the lines under the name and the notes; only the dishes and the
// wine list keep a left edge. Ragged text is hyphenated only with bodyText.hyphenation.ragged,
// so no word on this card is divided, the French dish names included. The config's locale
// names each edition's language, English or Spanish, for the bundle the Sandbox opens.
const headings = { fontFamily: DISPLAY, fontWeight: 400, color: col('wine'), textAlign: 'center',
  levels: [ // Limelight ships one weight, 400, and no italic
    // The H1 break is off: by default an H1 opens a recto, which would part the name from the
    // awning and La Cave from its bottles.
    { level: 1, fontSize: pt(48), lineHeight: pt(3 * LEAD), breakBefore: { enabled: false },
      marginTop: pt(LEAD), marginBottom: pt(0) }, // three grid lines, one of air above
    { level: 2, lineHeight: pt(LEAD), advancedDesign: courseHead, // one line; #region heads
      marginTop: pt(LEAD), marginBottom: pt(0) }, // the dishes below add a line of their own
  ] };

headings.textAlign and bodyText.textAlign put everything but the dishes and the wine list on the card's centre line. lineHeight: pt(3 * LEAD) gives the 48 pt name three grid lines. Without it the name takes the default leading and four lines, the second line of notes moves onto a page of its own and the card runs to four pages. Level 1 turns the H1 break off, breakBefore: { enabled: false }, because the name and La Cave belong on the page of the drawing above them. Leave the default, { enabled: true, parity: 'always-odd' }, and each drawing stands alone on a page, seven pages in all. The config sets no locale: nothing on this card is justified, and ragged text is hyphenated only with bodyText.hyphenation.ragged on.

The whole recipe

Sandbox
// ═══ Postext Cookbook · Nº 052 · Bistro menu: prices on a tab stop ═══════════════════
// https://postext.dev/en/cookbook/bistro-menu
// Code: MIT · Text: original, in French (CC BY 4.0) · Drawings: generated in code (CC BY 4.0)
// Fonts: Limelight, Noticia Text, Josefin Sans (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// The autumn menu of an imaginary Paris bistro: two sides of one card, each dish a paragraph
// whose price a tab sends to the right margin, the wine list a table with no rules.
import {
  buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage, parseTSV,
  mergeCells,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'bistro-menu';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { ink: '#1f2a24', paper: '#f6efdf', // green-black text on cream card
  wine: '#6d1f2c', brass: '#a9823a', // the name, heads and labels; rules and the drawings' metal
  straw: '#e8d4a8', bottle: '#2f4235', sage: '#8a9a78', // awning stripes and labels; glass
  muted: '#6b6457' }; // the colophon
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
// The engine's defaults link to 'main-color' (#295aa3, a blue); this palette makes it the wine red.
const colorPalette = Object.entries({ ...palette, 'main-color': palette.wine })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [TEXT, DISPLAY, LABEL] = ['Noticia Text', 'Limelight', 'Josefin Sans'];
const [BODY, LEAD] = [10.5, 14.5]; // pt: the text, and the leading every table row keeps

// #region answer: dish on the left, price flush right: a tab stop at the end of the measure
// Each course is a :::paragraphs group in the dish style. Its one tab stop stands at the end of
// the measure and ends there the text after the tab, so `:tab **7**` sets the price flush right
// however long the dish is. A backslash at the end of the line breaks it: the dish and its
// translation are one paragraph, and the price shares the dish's first line.
const dish = { id: 'dish', name: 'Dish', textAlign: 'left', // the card is centred; a dish is not
  tabStops: [{ position: 'end', align: 'end' }],
  spaceBetween: pt(LEAD / 2), // half a line between two dishes: each dish 2½ lines of LEAD
  marginTop: pt(LEAD), // a line of air under the course head
  indent: pt(LEAD / 4), endIndent: pt(LEAD / 4) }; // in line with the wine list's cell text
// The wine list stays a table: its prices stand in two columns under the heads 12 cl and 75 cl.
// The document's tableStyle turns off every rule and fill (#region wines).
const tableStyle = { rules: 'none', cellPadding: pt(LEAD / 4), // a row: 1½ lines of LEAD
  bodyFontFamily: TEXT, bodyFontSize: pt(BODY), bodyColor: col('ink'),
  headerFontFamily: LABEL, headerFontSize: pt(8.5), headerColor: col('wine'),
  headerBackgroundEnabled: false }; // header cells: the wine list's labels
// #endregion

// #region type: one resource type for the whole card: set where it stands, never numbered
// No caption prefix and no caption, so no 'Table 1' line prints under the wine list. Placement
// 'here' sets each piece at its ::resource line; a list that outgrows the page is cut
// between rows and goes on at the head of the next one.

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

#Stop the rules at a fixed length

A fixed width in place of 'fill' keeps each rule 20 mm long and 4 mm from the title, so the pair sits closer to the centre beside PLATS than beside LE COMPTOIR.

-    size: { width: 'fill' }, // to the column's edge
+    size: { width: mm(20) }, // 20 mm, wherever the title ends

#Run dots to the price

A leader fills the room before the stop. '. ' repeats a full stop and a space, from half an em after the dish's last badge or word to half an em before its price.

-  tabStops: [{ position: 'end', align: 'end' }],
+  tabStops: [{ position: 'end', align: 'end', leader: '. ' }],

#Rule the wine list like a ledger

rules: 'horizontal' draws a 0.5 pt brass hairline over and under every row of the wine list. Rules take no room, so both sides keep their layout, and the blank rows above Blancs and Rouges get a pair of hairlines of their own.

-const tableStyle = { rules: 'none', cellPadding: pt(LEAD / 4), // a row: 1½ lines of LEAD
+const tableStyle = { rules: 'horizontal', borderColor: col('brass'),
+  borderWidth: pt(0.5), cellPadding: pt(LEAD / 4),

Pitfalls

Pitfall

Merged cells need hiddenBy placeholders: use mergeCells

Cells are laid out by their position in the row array, so a merged cell needs placeholder cells marked hiddenBy where it spreads; leaving them out, as HTML does, shifts every later column. Build merges with mergeCells. Since postext 1.5 a table whose grid is irregular is reported in doc.contentWarnings as raggedTableGrid, and parseTSV(text, { headerRows }) marks the head rows. Tables from data →

Leave room for the price on the dish's first line. When the dish and the garnish run past the place the price needs, the stop takes the dish's last word down to the next line with the price, and the English line comes after them: the dish then takes three lines and the course ends a line lower.

Credits

Text
Original prose, CC BY 4.0
Images
  • The awning and the shelf of bottles, drawn in code in the page's palette · Ignacio Ferro · CC BY 4.0
Fonts
Limelight (SIL OFL 1.1) · Noticia Text (SIL OFL 1.1) · Josefin Sans (SIL OFL 1.1)
Sandbox