Kurz gesagt
Eine zweiseitige Speisekarte für ein erfundenes Pariser Restaurant. Sie zeigt, wie ein Tabulator jeden Preis an den rechten Rand schiebt und wie eine Weinkarte als Tabelle ohne sichtbare Linien entsteht.
Was Sie setzen
Die Herbstkarte von Les Tanneurs, einem erfundenen Pariser Bistro: ein Blatt, 230 × 310 mm, beidseitig bedruckt. Vorn hängt eine gestreifte Markise über dem Namen, gesetzt in der Limelight. Jeder Gangtitel steht zwischen zwei Messinglinien, die bis an die Ränder laufen, darunter vier Gerichte. Ein Gericht besteht aus seinem französischen Namen fett mit der Beilage, darunter einer englischen Zeile kursiv und dem Preis fett, rechtsbündig. Eine dunkelgrüne V-Scheibe kennzeichnet die vegetarischen Gerichte, eine umrissene SG-Pille die glutenfreien. Jedes Gericht ist ein Absatz, und ein Tabulator rückt seinen Preis an einen Tabstopp am rechten Rand. Hinten steht die Weinkarte unter einem Bord mit Flaschen, die Glas- und Flaschenpreise in Spalten mit den Köpfen 12 cl und 75 cl, in einer Tabelle ohne Linien und ohne Legende.
Dieses Rezept beantwortet
- Wie erstelle ich eine Tabelle mit Kopfzeilen, verbundenen Zellen, Spaltenbreiten und Ausrichtung je Zelle?
- Wie erstelle ich Inline-Chips: Tastaturtasten, Schlagwörter, Wortspeicher für Übungen?
- Wie setze ich nicht nummerierte Grafiken: Ornamente, Vignetten, Logos?
- Wie füge ich Bilder und Tabellen im Code (Ressourcen) statt mit Markdown ![]() hinzu?
Die kurze Antwort
// 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
Zutaten
- Funktionen
- Tabulatoren und FüllzeichenAbsatzformateTabellen aus DatenGestaltungselemente verankernTabellenformatInline-ChipsGestaltete AuftakteText, Linien und Kästen in SeitengestaltungenEigene RessourcentypenAbbildungen genau hierAbbildungen und Tabellen als RessourcenPapierfarbeÜberschriftenebenenSemantische FarbpaletteSeiten- und SpaltenumbrücheSeiten auf einem Canvas
- Schrift
- Limelight, Noticia Text, Josefin Sans (SIL OFL 1.1)
- Dateien
- The awning and the shelf of bottles, drawn in code in the page's palette (Ignacio Ferro, CC BY 4.0)
Zubereitung
#1 · Ein Tabstopp, wo der Preis steht
Der Code steht oben in der kurzen Antwort. Jeder Gang ist eine Gruppe :::paragraphs{style="dish"}, ein Absatz pro Gericht (Absatzformate). Das Format dish hat einen Tabstopp bei 'end', dem Ende der Satzbreite, mit align: 'end': Der Text nach einem Tabulator endet auf dem Stopp. So rückt :tab **7** nach der Beilage und den Zeichen den Preis an den rechten Rand, wie lang das Gericht auch ist (Tabulatoren und Tabstopps). :tab schluckt die Leerzeichen um sich herum, und der Backslash am Zeilenende ist ein erzwungener Zeilenumbruch, sodass die englische Zeile kursiv eine zweite Zeile desselben Absatzes beginnt und der Preis auf der ersten bleibt. spaceBetween setzt eine halbe Zeile zwischen zwei Gerichte, jedes Gericht nimmt also zweieinhalb Zeilen des Zeilenabstands von 14,5 pt ein. indent und endIndent von einer Viertelzeile halten die Gerichte auf der Flucht des Textes in den Zellen der Weinkarte auf der Rückseite. Ein Absatz mit Tabulatoren wird Zeile für Zeile gesetzt; hier steht ohnehin jede Zeile im Flattersatz.
#2 · Ein Ressourcentyp, an Ort und Stelle und nie nummeriert
// 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 });
Die eingebauten Typen für Abbildungen und Tabellen geben eine Legendenzeile aus und lassen jede Ressource an den ersten freien Platz nach ihrem ersten Verweis gleiten. Der Typ menu hat kein Legendenpräfix, und seine Teile haben keine Legende, deshalb steht unter den Zeichnungen und der Weinkarte nichts. Geben Sie ihm captionPrefix: 'Menu', und unter jedem Teil erscheint eine nummerierte Zeile, beginnend mit „Menu 1.“ unter der Markise, was die Karte auf vier Seiten bringt. defaultPlacement setzt die Weinkarte und jede Zeichnung an ihre Zeile ::resource (Blockeinbettung). Ohne diese Angabe gleitet die Weinkarte an den Fuß der Rückseite, unter „Le Comptoir“ und das Impressum. Die Markise und die Flaschen sind SVG-Ressourcen desselben Typs, im Code gezeichnet und mit loadSvg aus dem Kit registriert.
#3 · Die Regionszeilen verbinden
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 } });
}
Die Weinkarte bleibt eine Tabelle: Ihre beiden Preise stehen in Spalten unter ihren Köpfen, 12 cl und 75 cl, die eine Reihe von Tabstopps ohne Kopf ließe. parseTSV(tsv, { headerRows: 1 }) behandelt die erste Zeile als Kopfzeile, sodass „Appellation · cépage“, „12 cl“ und „75 cl“ über ihren Spalten in der Kopfschrift stehen, der Josefin Sans. Eine Zeile mit nur einem Feld gibt eine Region an. Ihre Zelle wird zu einer zentrierten Kopfzelle, und mergeCells zieht sie über die drei Spalten und markiert die beiden Zellen, die sie überdeckt, mit hiddenBy (Tabellenmodelle aufbauen). Zentriert allein in der ersten Spalte stünde „BLANCS“ 22,6 mm links der Achse, auf der „La Cave“ und „Le Comptoir“ zentriert sind. Eine Leerzeile im TSV wird zu einer Zeile leerer Zellen, anderthalb Zeilen hoch, und diese Zeile ist der Abstand über „Blancs“ und „Rouges“.
#4 · Eine Linie an jede Seite des Gangtitels hängen
// 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),
] } };
Ein Gangtitel ist eine Gestaltung in der Spalte. Das Element {titleText} hat keine Breite, sein Rechteck ist also so breit wie seine Versalien, und der Bezugspunkt 'top' zentriert ihn in der Spalte. Jede Linie hängt mit 'left-of' oder 'right-of' an einer Kante des Titels und füllt bis zum Rand der Spalte (Platzierung von Elementen), sodass die Linien neben „PLATS“ 66,7 mm lang sind und die neben „LE COMPTOIR“ 56,2 mm, jede 4 mm von den Buchstaben entfernt. Das lineHeight des Titels ist ein Faktor, 0.96, der sein Rechteck 14,4 pt hoch macht und ihn innerhalb einer Rasterzeile von 14,5 pt hält. Bei 1 ist das Rechteck 15 pt hoch, jeder Titel nimmt zwei Zeilen ein, und die Karte läuft auf vier Seiten.
#5 · Zeichen als Chips, Kleingedrucktes als Absatzformate
// 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) },
];
Ein Chip zeichnet ein Rechteck um ein Stück Text innerhalb der Zeile (Chip-Formate), sodass :chip[V]{style="veg"}, nach der Beilage getippt, die Scheibe vor dem Tabulator auf die französische Zeile des Gerichts setzt. Die Chip-Stile setzen bold: true, weil ein Chip die Schriftstärke des umgebenden Textes übernimmt, nach einer Beilage 400, und FONTS die Josefin Sans nur in 700 lädt. Die Hinweise unter den Desserts und das Impressum auf der Rückseite sind Blöcke :::paragraphs in 9 und 7,5 pt, und beide Formate haben ein marginTop von einer Zeile (Absatzformate). Ohne diesen Abstand beginnen die Hinweise auf der Zeile nach der englischen Zeile der Käseplatte, als gehörten sie zum Gericht.
#6 · Die Karte auf eine Achse zentrieren
// 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 und bodyText.textAlign stellen alles außer den Gerichten und der Weinkarte auf die Mittelachse der Karte. lineHeight: pt(3 * LEAD) gibt dem Namen in 48 pt drei Rasterzeilen. Ohne diese Angabe nimmt der Name den Standardzeilenabstand und vier Zeilen ein, die zweite Zeile der Hinweise rückt auf eine eigene Seite, und die Karte läuft auf vier Seiten. Ebene 1 schaltet den Umbruch vor H1 ab, breakBefore: { enabled: false }, weil der Name und „La Cave“ auf die Seite der Zeichnung über ihnen gehören. Bleibt der Standardwert { enabled: true, parity: 'always-odd' }, steht jede Zeichnung allein auf einer Seite, sieben Seiten insgesamt. Die Konfiguration setzt keine locale: Nichts auf dieser Karte steht im Blocksatz, und Flattersatz wird nur mit eingeschaltetem bodyText.hyphenation.ragged getrennt.
Das ganze Rezept
// ═══ 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.
Das zusammengesetzte script.js läuft unverändert: Fügen Sie es in das Modulskript einer beliebigen Seite ein, oder öffnen Sie das Rezept auf CodePen. Ordner des Rezepts auf GitHub ↗ (öffnet sich in einem neuen Tab)
Varianten
#Die Linien bei fester Länge enden lassen
Eine feste Breite statt 'fill' hält jede Linie 20 mm lang und 4 mm vom Titel entfernt, sodass das Paar neben „PLATS“ näher an der Mitte sitzt als neben „LE COMPTOIR“.
- size: { width: 'fill' }, // to the column's edge
+ size: { width: mm(20) }, // 20 mm, wherever the title ends#Punkte bis zum Preis führen
Eine Füllzeichenfolge füllt den Raum vor dem Stopp. '. ' wiederholt einen Punkt und ein Leerzeichen, von einem halben Geviert nach dem letzten Zeichen oder Wort des Gerichts bis ein halbes Geviert vor seinen Preis.
- tabStops: [{ position: 'end', align: 'end' }],
+ tabStops: [{ position: 'end', align: 'end', leader: '. ' }],#Die Weinkarte wie ein Kassenbuch linieren
rules: 'horizontal' zieht eine Haarlinie in Messing von 0,5 pt über und unter jede Zeile der Weinkarte. Linien nehmen keinen Raum ein, beide Seiten behalten also ihr Layout, und die leeren Zeilen über „Blancs“ und „Rouges“ bekommen ein eigenes Paar Haarlinien.
-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),Häufige Fehler
Lassen Sie auf der ersten Zeile des Gerichts Platz für den Preis. Laufen Gericht und Beilage über die Stelle hinaus, die der Preis braucht, nimmt der Stopp das letzte Wort des Gerichts mit dem Preis auf die nächste Zeile mit, und die englische Zeile folgt danach: Das Gericht nimmt dann drei Zeilen ein, und der Gang endet eine Zeile tiefer.
Nachweise
- Rezept
- Ignacio Ferro
- Text
- Eigener Text, CC BY 4.0
- Bilder
- The awning and the shelf of bottles, drawn in code in the page's palette · Ignacio Ferro · CC BY 4.0
- Schriften
- Limelight (SIL OFL 1.1) · Noticia Text (SIL OFL 1.1) · Josefin Sans (SIL OFL 1.1)
- Code
- MIT, wie Postext
Diesen Text bearbeiten ↗ (öffnet sich in einem neuen Tab)Ordner des Rezepts auf GitHub ↗ (öffnet sich in einem neuen Tab)


