本文へスキップ
レシピ番号52

レシピ集 · 第8章 · 表

ビストロのメニュー:価格をタブ位置にそろえる

両面刷りのビストロのメニューです。価格はタブ位置で右端にそろえ、ワインリストは罫のない表に組み、コースの見出しの左右には真鍮色の罫を1本ずつ添えます。

このページの内容

1ページ(全2ページ)

  • 英語の見本:日本語版はまだありません
  • 仕上がり230 × 310 mm
  • 1段
  • Noticia Text 10.5/14.5
  • Josefin Sans
  • Limelight
  • 2ページ
  • レベル
  • Postext 1.57.1
  • 組版時間47 ms
  • コード154行

かんたんな説明

パリにある架空のレストランの両面メニューです。タブで価格を右端へ送る方法と、罫の見えない表にワインリストを組む方法を示します。

できあがり

架空のパリのビストロ、Les Tanneursの秋のメニューです。230 × 310mmの1枚の紙の両面に刷ります。表面では、ストライプの日よけがLimelightで組んだ店名の上に掛かります。コースの見出しはそれぞれ余白まで伸びる2本の真鍮色の罫に挟まれ、その下に4品の料理が並びます。料理は、付け合わせを添えた太字のフランス語の名前、その下のイタリックの英語の行、右端にそろえた太字の価格でできています。濃い緑のVの円形マークはベジタリアン料理を、輪郭線だけのSGの角丸マークはグルテンフリーの料理を示します。料理はそれぞれ1つの段落で、タブが価格を右の余白のタブ位置へ送ります。裏面では、ボトルの棚の下にワインリストがあり、グラスとボトルの価格が12 clと75 clの見出しの下に列をなします。この列は、罫もキャプションもない表に組んであります。

このレシピが答える質問

  • 見出し行、結合セル、列幅、セルごとのそろえを備えた表を作るには?
  • キーボードのキー、タグ、練習問題の語群などのインラインのチップを作るには?
  • 番号のないアートワーク(オーナメント、カット、ロゴ)を組むには?
  • 画像や表を、Markdownの![]()ではなくコードから(リソースとして)追加するには?

手短な答え

script.js · 28〜42行コード全体で見る
// 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

材料

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

作り方

#1 · 価格を置く場所にタブ位置を

コードは上の手短な答えにあります。コースはそれぞれ:::paragraphs{style="dish"}グループで、1品が1段落です(段落スタイル)。料理のスタイルには、行長の終わりである'end'にタブ位置が1つだけあり、align: 'end'を指定しています。タブのあとのテキストは、このタブ位置で終わります。そのため、付け合わせとマークのあとに:tab **7**と書けば、料理名の長さにかかわらず価格が右の余白にそろいます(タブとタブ位置)。:tabは前後のスペースを含みます。行末のバックスラッシュは強制改行なので、イタリックの訳は同じ段落の2行目から始まり、価格は1行目に残ります。spaceBetweenが料理と料理のあいだに半行を空けるので、各料理は14.5ptの行送りの2.5行分を取ります。行の4分の1のindentとendIndentで、料理を裏面のワインリストのセルの文字にそろえます。タブを含む段落は1行ずつ組まれますが、ここではどの行ももともとラグ組みです。

#2 · 番号を振らず、その場に置く1つのリソースタイプ

script.js · 46〜53行コード全体で見る
// 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 });

組み込みの図と表のタイプは、キャプションの行を印刷し、各リソースを最初の参照のあとの最初の空き位置にフロートとして配置します。menuタイプにはキャプションの接頭辞がなく、各ピースにもキャプションがないので、画像やワインリストの下には何も印刷されません。captionPrefix: 'Menu'を与えると、日よけの下の「Menu 1.」から始まる番号付きの行がすべてのピースの下に印刷され、メニューは4ページになります。defaultPlacementは、ワインリストと各図をそれぞれの::resourceの行に置きます(ブロックの埋め込み)。これがないと、ワインリストは裏面の地までフロートし、Le Comptoirと奥付の下に置かれます。日よけとボトルは同じタイプのSVGリソースで、コードで描いてキットのloadSvgで登録します。

#3 · 産地の行を結合する

script.js · 57〜70行コード全体で見る
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 } });
}

ワインリストは表のままです。2つの価格がそれぞれ12 clと75 clの見出しの下に列をなしますが、タブ位置を並べただけでは列に見出しを付けられません。parseTSV(tsv, { headerRows: 1 })が最初の行を見出し行として読むので、Appellation · cépage、12 cl、75 clがそれぞれの列の上に、見出しの書体Josefin Sansで印刷されます。フィールドが1つしかない行は産地の名前です。そのセルは中央そろえの見出しセルになり、mergeCellsがそれを3列に広げて、覆われる2つのセルにhiddenByを付けます(表モデルの構築)。1列目の中だけで中央にそろえると、BLANCSは、La CaveとLe Comptoirがそろう中心線から22.6mm左に立ってしまいます。TSVの空行は空のセルが並ぶ1.5行分の高さの行になり、この行がBlancsとRougesの上のアキになります。

#4 · コースの題の両側に罫を掛ける

script.js · 74〜88行コード全体で見る
// 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),
] } };

コースの見出しは段の中のデザインです。{titleText}要素には幅がないので、その箱は大文字の幅だけになり、'top'アンカーがそれを段の中央に置きます。罫は'left-of'または'right-of'で題の片側の端に掛け、段の端まで伸ばします(要素の配置)。そのため、PLATSの両側の罫は66.7mm、LE COMPTOIRの両側は56.2mmになり、どれも文字から4mm離れます。題のlineHeightは倍率の0.96で、箱は14.4ptとなり、14.5ptのグリッド1行に収まります。1にすると箱は15ptになり、見出しがそれぞれ2行を取って、メニューは4ページになります。

#5 · マークはチップで、細かい文字は段落スタイルで

script.js · 92〜110行コード全体で見る
// 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) },
];

チップは行の中の文字列を箱で囲みます(チップスタイル)。付け合わせのあとに:chip[V]{style="veg"}と書けば、料理のフランス語の行の、タブの前に円形マークが付きます。チップは周りの文字のウェイト、付け合わせのあとなら400を受け継ぎますが、FONTSはJosefin Sansを700しか読み込まないので、チップスタイルにはbold: trueを設定します。デザートの下の注記と裏面の奥付は9ptと7.5ptの:::paragraphsブロックで、どちらのスタイルも1行分のmarginTopを取ります(段落スタイル)。このアキがないと、注記はチーズの盛り合わせの英語の行のすぐ次の行から始まり、その料理の一部のように見えます。

#6 · メニューを1本の軸で中央にそろえる

script.js · 114〜126行コード全体で見る
// 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とbodyText.textAlignは、料理とワインリスト以外のすべてをメニューの中心線に置きます。lineHeight: pt(3 * LEAD)は48ptの店名にグリッド3行分を与えます。これがないと店名は既定の行送りで4行分を取り、注記の2行目が別のページに送られて、メニューは4ページになります。レベル1はbreakBefore: { enabled: false }でH1の改ページを切ります。店名とLa Caveは、その上の画像と同じページに属するからです。既定値の{ enabled: true, parity: 'always-odd' }のままにすると、画像がそれぞれ1ページを占め、全部で7ページになります。設定にlocaleは入れていません。このメニューには両端そろえの箇所がなく、ラグ組みのテキストがハイフネーションされるのはbodyText.hyphenation.raggedをオンにしたときだけだからです。

レシピの全体

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.

組み立てたscript.jsはそのまま動きます。任意のページのモジュールスクリプトに貼り付けるか、レシピをCodePenで開いてください。 GitHub上のレシピのフォルダー ↗ (新しいタブで開きます)

アレンジ

#罫を一定の長さで止める

'fill'の代わりに固定の幅を与えると、罫はどれも20mmの長さで題から4mm離れます。そのため、PLATSの両側の罫はLE COMPTOIRの両側より中心寄りに並びます。

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

#価格まで点を並べる

リーダーはタブ位置の前のアキを埋めます。'. 'はピリオドとスペースを繰り返し、料理の最後のマークまたは最後の語の0.5em後から、価格の0.5em前まで続きます。

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

#帳簿のようにワインリストの行ごとに罫を引く

rules: 'horizontal'は、ワインリストのすべての行の上下に0.5ptの真鍮色の細い罫を引きます。罫は場所を取らないので両面ともレイアウトは変わらず、BlancsとRougesの上の空の行にもそれぞれ1組の罫が付きます。

-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),

よくあるつまずき

つまずき

結合セルにはhiddenByのプレースホルダーが要る。mergeCellsを使う

セルは行の配列内の位置で配置されるため、結合セルが広がる位置にはhiddenByを付けたプレースホルダーのセルが必要です。HTMLのように省くと、それ以降の列がすべてずれます。結合はmergeCellsで作ってください。postext 1.5からは、グリッドが不ぞろいな表はdoc.contentWarningsにraggedTableGridとして報告され、parseTSV(text, { headerRows })でヘッダー行を指定できます。 データから作る表 →

料理の1行目に価格の入る場所を残してください。料理名と付け合わせが価格に必要な位置を越えると、タブ位置は料理名の最後の語を価格と一緒に次の行へ送り、英語の行はそのあとに続きます。すると料理は3行を取り、コースは1行下で終わります。

クレジット

レシピ
Ignacio Ferro
本文
書き下ろしの文章, CC BY 4.0
画像
  • The awning and the shelf of bottles, drawn in code in the page's palette · Ignacio Ferro · CC BY 4.0
フォント
Limelight (SIL OFL 1.1) · Noticia Text (SIL OFL 1.1) · Josefin Sans (SIL OFL 1.1)
Sandbox