انتقل إلى المحتوى الرئيسي
الوصفة رقم 52

دليل الوصفات · الفصل 8 · الجداول

قائمة مطعم: الأسعار على موضع جدولة

قائمة مطعم صغير على وجهين: أسعار ملاصقة لليمين على موضع جدولة، والنبيذ في جدول بلا حدود، وخط نحاسي مثبّت على كل جانب من عنوان كل صنف.

في هذه الصفحة
  • نموذج باللغة الإنجليزية: لا توجد طبعة عربية بعد
  • مقاس القص 230 × 310 مم
  • عمود واحد
  • Noticia Text 10.5/14.5
  • Josefin Sans
  • Limelight
  • صفحتان
  • المستوى
  • Postext 1.57.1
  • أُخرجت في 47 ms
  • أسطر الشيفرة: 154

باختصار

قائمة طعام بوجهين لمطعم باريسي متخيَّل. تبيّن كيف تدفع كل سعر إلى الحافة اليمنى بجدولة، وكيف تنضّد قائمة نبيذ في جدول لا تظهر فيه أي خطوط.

ما الذي ستنضده

قائمة الخريف لمطعم Les Tanneurs، وهو مطعم باريسي متخيَّل: ورقة واحدة مقاسها 230 × 310 mm مطبوعة على الوجهين. على الوجه تتدلى مظلة مخططة فوق الاسم المنضّد بخط Limelight. كل عنوان صنف يقف بين خطين نحاسيين يمتدان إلى الهامشين، وتحته أربعة أطباق. الطبق هو اسمه الفرنسي بالأسود العريض مع المرافقات، وتحته سطر إنجليزي بالمائل، والسعر بالأسود العريض ملاصقًا للحافة اليمنى. قرص أخضر داكن عليه V يدلّ على الأطباق النباتية، وكبسولة محددة الإطار عليها SG على الأطباق الخالية من الغلوتين. كل طبق فقرة واحدة، وترسل الجدولة سعره إلى موضع عند الهامش الأيمن. على الظهر تأتي قائمة النبيذ تحت رف من الزجاجات، وسعر الكأس وسعر الزجاجة في عمودين عنوانهما 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"}، فقرة لكل طبق (أنماط الفقرات). لنمط الطبق موضع جدولة واحد، عند 'end'، أي نهاية عرض السطر، مع align: 'end': النص الذي يلي الجدولة ينتهي عند الموضع. لذلك يرسل :tab **7** بعد المرافقات والشارات السعرَ إلى الحافة اليمنى مهما طال الطبق (الجدولة ومواضع الجدولة). يضمّ :tab المسافات المحيطة به، والشرطة المائلة العكسية في آخر السطر كسر سطر قسري، فتبدأ الترجمة بالمائل سطرًا ثانيًا من الفقرة نفسها ويبقى السعر في السطر الأول. ويضع spaceBetween نصف سطر بين طبقين، فيأخذ كل طبق سطرين ونصفًا من تباعد الأسطر البالغ 14.5 pt. ويحاذي indent وendIndent، وكل منهما ربع سطر، الأطباقَ مع نص خلايا قائمة النبيذ على الظهر. الفقرة التي فيها جدولة تُنضَّد سطرًا سطرًا، والأسطر هنا كلها غير مضبوطة على أي حال.

#2 · نوع مورد واحد، في مكانه ومن غير ترقيم

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.» تحت المظلة، وتمتد القائمة إلى أربع صفحات. يضع 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 } });
}

تبقى قائمة النبيذ جدولًا: سعراها في عمودين تحت عنوانيهما، 12 cl و75 cl، وصفّ من مواضع الجدولة يتركهما بلا عنوان. تقرأ parseTSV(tsv, { headerRows: 1 }) السطر الأول صفَّ عناوين، فتُطبع Appellation · cépage و12 cl و75 cl فوق أعمدتها بخط العناوين، Josefin Sans. السطر الذي فيه حقل واحد هو اسم منطقة. تصبح خليته خلية عنوان في الوسط، وتمدّها mergeCells على الأعمدة الثلاثة وتعلّم الخليتين اللتين تغطيهما بـhiddenBy (بناء نماذج الجداول). لو توسّطت BLANCS العمود الأول وحده لوقفت على بعد 22.6 mm يسار المحور الذي تتوسطه La Cave وLe Comptoir. والسطر الفارغ في ملف TSV يصبح صفًّا من الخلايا الفارغة بارتفاع سطر ونصف، وهذا الصف هو الفراغ فوق 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.7 mm وبجانب LE COMPTOIR 56.2 mm، وكل منهما على بعد 4 mm من الحروف. قيمة lineHeight للعنوان مضاعف، 0.96، فيصير مستطيله 14.4 pt ويبقى داخل سطر واحد من الشبكة البالغ 14.5 pt. مع القيمة 1 يصير المستطيل 15 pt، ويأخذ كل عنوان سطرين، وتمتد القائمة إلى أربع صفحات.

#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) مستطيلًا حول مقطع من النص داخل السطر (أنماط الشارات)، فإذا كتبت :chip[V]{style="veg"} بعد المرافقات ظهر القرص على السطر الفرنسي للطبق، قبل الجدولة. تضبط أنماط الشارات bold: true لأن الشارة تأخذ وزن النص المحيط بها، أي 400 بعد المرافقات، وFONTS لا يحمّل Josefin Sans إلا بالوزن 700. الملاحظات تحت الحلوى وبيانات الطبع على الظهر كتل :::paragraphs بحجمَي 9 و7.5 pt، ولكلا النمطين marginTop قدره سطر واحد (أنماط الفقرات). من دون هذا الهامش تبدأ الملاحظات على السطر التالي لسطر طبق الأجبان الإنجليزي، كأنها جزء من الطبق.

#6 · ضع القائمة كلها على محور واحد

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) الاسمَ المنضّد بحجم 48 pt يأخذ ثلاثة أسطر من الشبكة. من دونه يأخذ الاسم تباعد الأسطر الافتراضي وأربعة أسطر، فينتقل السطر الثاني من الملاحظات إلى صفحة وحده وتمتد القائمة إلى أربع صفحات. يُلغي المستوى 1 فاصل الصفحة قبل H1 بـbreakBefore: { enabled: false }، لأن الاسم وLa Cave مكانهما في صفحة الرسم الذي فوقهما. اترك القيمة الافتراضية، { enabled: true, parity: 'always-odd' }، فيقف كل رسم وحده في صفحة، سبع صفحات في المجموع. لا يضبط الإعداد أي 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 المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)

تنويعات

#أوقف الخطوط عند طول ثابت

عرض ثابت مكان 'fill' يبقي كل خط بطول 20 mm وعلى بعد 4 mm من العنوان، فيقترب الزوج من الوسط بجانب PLATS أكثر مما بجانب LE COMPTOIR.

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

#مدّ النقاط إلى السعر

يملأ خط الإرشاد المساحة التي قبل الموضع. يكرّر '. ' نقطة ومسافة، من نصف em بعد آخر شارة أو آخر كلمة في الطبق إلى نصف em قبل سعره.

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

#سطّر قائمة النبيذ كدفتر الحسابات

يرسم rules: 'horizontal' خطًّا نحاسيًا رفيعًا بسماكة 0.5 pt فوق كل صف من صفوف قائمة النبيذ وتحته. الخطوط لا تأخذ مساحة، فيحتفظ الوجهان بإخراجهما، ويحصل كل من الصفين الفارغين فوق Blancs وRouges على زوج خطوط خاص به.

-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 }) صفوف الترويسة. جداول من البيانات →

اترك للسعر مكانًا في السطر الأول من الطبق. حين يتجاوز الطبق والمرافقات الموضع الذي يحتاجه السعر، يأخذ الموضع الكلمة الأخيرة من الطبق إلى السطر التالي مع السعر، ويأتي السطر الإنجليزي بعدهما: فيأخذ الطبق ثلاثة أسطر وينتهي الصنف أدنى بسطر.

الحقوق

الوصفة
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)
الشيفرة
MIT، مثل Postext
Sandbox