باختصار
كتالوج بذور من أربع صفحات فيه قائمة أسعار. لكل صنف من البذور رسم صغير لكيسه داخل الجدول، والقائمة تستمر على صفحتين متقابلتين.
ما الذي ستنضده
قائمة أسعار الربيع لـBrindlewood Seed Co.، وهي مزرعة بذور متخيَّلة، في كتيّب من أربع صفحات على ورق بلون الجلد المدبوغ. ينضّد الغلاف Spring Seeds بخط Alfa Slab One فوق رسم ملوّن لزهرة عبّاد شمس ونبتة طماطم، وتحته الرسالة إلى المزارعين في عمودين. في الصفحتين 2 و3 القائمة. لكل صنف رسم لكيس بذوره في أعلى خليته واسمه تحته، وأنواع الخضار تمتد نزولًا في عمود أول مدمج. الأسعار ملاصقة للحافة اليمنى بخط تسميات مضغوط، وشارات حمراء وخضراء تعلّم البذور الجديدة والعضوية. تنقطع القائمة بعد الفلفل المخصص للقلي وتُستأنف في الصفحة المقابلة تحت الشريط الأحمر نفسه، موسومة بـ (continued). الصفحة الأخيرة استمارة الطلب: شبكتان بزوايا مدوّرة فيهما أسطر فارغة للكتابة.
تجيب هذه الوصفة عن
- كيف أضع صورًا أو أيقونات داخل خلايا الجدول؟
- كيف أقسّم جدولًا طويلًا عبر الصفحات مع تكرار الرأس وعلامة «تابع»؟
- كيف أنسّق عدة جداول تنسيقات مختلفة (تعبئة، خلايا مخططة بالتناوب، أطر مستديرة) في مستند واحد؟
- كيف أصنع جدولًا فيه صفوف رأس، وخلايا مدمجة، وعروض أعمدة، ومحاذاة لكل خلية؟
الجواب المختصر
const at = (row, c) => ({ row, col: c });
const slug = (name) => name.toLowerCase().replace(/\W+/g, '-'); // 'Gold Medal' → 'gold-medal'
function priceList(tsv) { // Kind · Variety · Description · Packet · Ounce, under one head row
let m = { ...parseTSV(tsv, { headerRows: 1 }), columnWidths: [20, 40, 63, 17, 17] }; // mm
for (const c of [0, 1]) m = setAlignment(m, at(0, c), 'center'); // each head over its column
for (const c of [3, 4]) m = setAlignment(m, at(0, c), 'right');
for (let r = 1; r < m.rows.length; r++) {
// The picture is a resource of its own; the cell sets it at the top, centred, with the
// variety's name under it, and the row grows to hold both.
const variety = m.rows[r][1].content;
m = setCellImage(m, at(r, 1), { resourceId: slug(variety), width: PACKET });
m = setCellContent(m, at(r, 1), `**${variety}**`);
m = setAlignment(m, at(r, 1), 'center');
for (const c of [3, 4]) { // prices in the label face: lining figures, flush right
m = setCellContent(m, at(r, c), `:chip[$${m.rows[r][c].content}]{style="price"}`);
m = setAlignment(m, at(r, c), 'right');
}
if (!m.rows[r][0].content) continue; // an empty Kind goes on with the one above
let end = r;
while (m.rows[end + 1] && !m.rows[end + 1][0].content) end++;
// One cell down the rows of its kind; mergeCells leaves the covered cells in the grid,
// marked hiddenBy (gotcha: merged-cells-hiddenby). A split never cuts through it.
m = mergeCells(m, { start: at(r, 0), end: at(end, 0) });
m = setAlignment(m, at(r, 0), 'center', 'middle');
m = setCellBackground(m, at(r, 0), col('cream'));
}
return m;
}
// The letter on page 1 cites the list, so it floats to the first free slot after the
// letter, page 2, and is cut between rows where the page ends; span 'page' gives it the
// full 157 mm, not a 75 mm column.
const vegetableList = (tsv) => ({ id: 'vegetables', typeId: 'list', kind: 'table',
caption: '**Vegetable Seeds**', placement: { span: 'page' },
note: 'A packet holds about 30 tomato or pepper seeds, 40 beans or 12 squash seeds.',
table: { model: priceList(tsv) }, createdAt: 0, updatedAt: 0 });
المكونات
- الميزات
- صور في خلايا الجداولجداول عبر الصفحاتجداول من البياناتأنماط الجداول المسمّاةنمط الجدولتعبئة الخلايانمط التعليقالشارات داخل السطرأنواع موارد مخصّصةالأشكال والجداول بوصفها مواردموضع الأشكالاستشهادات تضع الأشكالأنماط العناوينسمات العنوانصفحات افتتاح مصمَّمةالصور في تصاميم الصفحةالأغلفة وصفحات العنوان وبيانات النشرالترويسات وأرقام الصفحاتلون الورقلوحة ألوان دلالية
- تستخدم أيضًا
- أشكال في هذا الموضع بالضبطالترويسات بحسب دور الصفحةأنماط الفقراتهندسة القسمترويسات لكل قسم
- الخطوط
- Gelasio, Alfa Slab One, Cabin Condensed (SIL OFL 1.1)
- الأصول
amish-paste-360.jpgblack-beauty-360.jpgbrandywine-360.jpgcherokee-purple-360.jpgcover-1500.jpgdragon-tongue-360.jpggold-medal-360.jpgjimmy-nardello-360.jpgkentucky-wonder-360.jpgwaltham-butternut-360.jpg- The cover's sunflower and tomato plant, a painting (Generated With Diffusion Models, أصلي)
- The Brandywine seed packet (Generated With Diffusion Models, أصلي)
- The Cherokee Purple seed packet (Generated With Diffusion Models, أصلي)
- The Gold Medal seed packet (Generated With Diffusion Models, أصلي)
- The Amish Paste seed packet (Generated With Diffusion Models, أصلي)
- The Jimmy Nardello seed packet (Generated With Diffusion Models, أصلي)
- The Kentucky Wonder seed packet (Generated With Diffusion Models, أصلي)
- The Dragon Tongue seed packet (Generated With Diffusion Models, أصلي)
- The Black Beauty seed packet (Generated With Diffusion Models, أصلي)
- The Waltham Butternut seed packet (Generated With Diffusion Models, أصلي)
طريقة التحضير
#1 · أضف ما يغفله ملف TSV
الشيفرة في الجواب المختصر أعلاه. ليس في ملف TSV إلا الكلمات والأسعار. تضع setCellImage كيس كل صنف، وهو مورد مسمّى باسم الصنف، في أعلى خليته بنسبة 55% من عرضها الداخلي، فيقع الاسم تحت صورة مقاسها 20.3 × 27.1 mm ويكبر كل صف إلى 36 mm. وتمدّ mergeCells كل نوع نزولًا في العمود الأول وتعلّم الخلايا التي تغطيها بـhiddenBy. خلايا متن الجدول تتشارك خطًّا واحدًا، Gelasio هنا، لذلك كل سعر شارة بلا تعبئة ولا حدّ ولا حشوة جانبية، منضّدة بخط Cabin Condensed العريض بحجم 1.12 em من أجل أرقامه المصطفة.
#2 · استشهد بالقائمة واقسمها على الصفحتين المتقابلتين
const tableStyle = { bodyFontSize: pt(9), headerFontFamily: LABEL, // body cells in Gelasio
headerFontSize: pt(7.5), headerColor: col('paper'), headerBackground: col('ink'),
rules: 'horizontal', borderColor: col('rule'), borderWidth: pt(0.5), cellPadding: mm(1.5),
// 'split' is the default, written out as the key to change: 'clip' keeps the rows that fit
// page 2 and drops the rest, 'hide' drops the whole list. Suffix and marker label the parts.
overflow: 'split', continuedSuffix: '(continued)',
continuesMarker: 'Continued on the facing page' };
const tableStyles = [{ id: 'form', rules: 'grid', borderRadius: mm(2.5), // a card to write on
borderColor: col('muted'), borderWidth: pt(0.6), headerBackground: col('basil'),
bodyFontFamily: LABEL, bodyFontSize: pt(8.5),
bodyBackgroundEnabled: true, bodyBackground: col('cream'), cellPadding: mm(1.6) }];
// The caption sits above the table on a tomato band and is repeated on every part. Its note
// and the marker take the caption's face, so the caption keeps the body's Gelasio, which has
// the italic the suffix and the marker are set in; Cabin Condensed has none.
const captionStyle = { fontSize: pt(12), color: col('cream'),
position: 'above', backgroundEnabled: true, background: col('tomato'), padding: mm(2),
gap: mm(0), note: { fontSize: pt(7.8), color: col('muted') } };
تستشهد الرسالة في الصفحة 1 بالقائمة بـ:ref{id="vegetables" text="the price list"}، وtext يطبع تلك الكلمات مكان الرقم. الجدول المستشهَد به يطفو إلى أول موضع فارغ بعد الاستشهاد، وهو هنا أعلى الصفحة 2. القائمة لا تتسع هناك، فيقطعها المحرّك بين الصفوف بعد Jimmy Nardello، ولا يقطع أبدًا داخل نوع مدمج. تكرّر الصفحة 3 صف الرأس وشريط التعليق مع اللاحقة؛ وتذهب العلامة تحت الجزء الأول والملاحظة تحت الأخير (الجداول الأطول من الصفحة). تجعل parseTSV(tsv, { headerRows: 1 }) الصف الأول صفَّ رأس، فيُرسم كذلك ويتكرر في الصفحة 3. اللاحقة والعلامة بالمائل وتأخذان خط التعليق، فيبقى الشريط بخط Gelasio؛ إذ ليس لخط Cabin Condensed مائل.
#3 · مورد لكل كيس
// Nothing cites the pictures, so none is numbered or placed: the cover design and the cells
// draw them by id, and their typeId is never looked up.
const picture = (id, fileId, [w, h], altText) => ({ id, typeId: 'figure', kind: 'bitmap',
altText, bitmap: { fileId, format: 'jpeg', width: w, height: h }, createdAt: 0, updatedAt: 0 });
const varieties = parseTSV(list).rows.slice(1).map((row) => row[1].content);
const resources = [vegetableList(list), shipTo, orderForm,
picture('cover-art', 'cover-1500.jpg', [1500, 1040], // the cover's 150 × 104 mm
'A sunflower and a staked tomato plant in a ploughed field.'),
...varieties.map((name) => picture(slug(name), `${slug(name)}-360.jpg`, [360, 480], // 3 : 4
`Seed packet of ${name}.`))];
await prepareFonts(markdown + list, config(), kitFonts(FONTS));
await Promise.all(resources.flatMap(({ bitmap }) => bitmap
? [loadImage(bitmap.fileId, asset(bitmap.fileId))] : []));
صورة الخلية تحدّد موردًا بمعرّفه، لذلك كل كيس مورد نقطي خاص به، ملف JPEG بمقاس 360 × 480 px مقصوص بنسبة الكيس 3 : 4، وتسجّله الدالة loadImage في الأدوات المساعدة تحت fileId بواسطة registerResourceImage. لا شيء يستشهد بالأكياس، فلا يُرقَّم أيٌّ منها ولا يوضع خارج خليته. الرسوم بلا كتابة: الاسم منضّد نصًّا في الخلية، بخطوط الصفحة.
#4 · نمط جدول ثانٍ لاستمارة الطلب
function form(id, widths, rows, merges, note) { // an empty cell still takes a line's height
let m = { headerRowCount: 1, columnWidths: widths, rows: rows.map((row, r) =>
widths.map((_, c) => ({ content: row[c] ?? '', isHeader: r === 0 }))) };
for (const [r, c0, c1] of merges) m = mergeCells(m, { start: at(r, c0), end: at(r, c1) });
m.rows.forEach((row, r) => row.forEach((cell, c) => { // a label takes the paper's buff
if (r === 0 || !cell.content || cell.hiddenBy) return;
m = setCellBackground(m, at(r, c), col('paper'));
if (cell.colSpan > 1) m = setAlignment(m, at(r, c), 'right'); // the totals' labels
}));
return { id, typeId: 'list', kind: 'table', note, placement: { position: 'here' },
table: { model: m, styleId: 'form' }, createdAt: 0, updatedAt: 0 };
}
const shipTo = form('ship-to', [24, 60, 24, 49], [['Ship to'], ['Name'], ['Street or box'],
['Town', '', 'State and ZIP']], [[0, 0, 3], [1, 1, 3], [2, 1, 3]]);
const lines = Array.from({ length: 11 }, () => []); // eleven varieties to a sheet
const orderForm = form('order', [16, 73, 20, 20, 28], [['No.', 'Variety', 'Packets', 'Ounces',
'Amount'], ...lines, ['Seeds total'], ['Postage: free on orders of $40 or more, otherwise $4.50'],
['**Total enclosed**']], [1, 2, 3].map((k) => [lines.length + k, 0, 3]),
'We guarantee every packet to grow. If a variety fails to come up in your garden, write to '
+ 'us before August 1 and we will send a new packet or refund what you paid for it.');
تستعمل الشبكتان النمط المسمّى form، بخطوط شبكية، ونصف قطر 2.5 mm للحدّ الخارجي، وتعبئة كريمية للكتابة عليها. وتحتفظ قائمة الأسعار بـtableStyle الخاص بالمستند (أنماط الجداول المسمّاة). الخلية الفارغة لا تحتاج إلى عنصر نائب، لأن صفها يأخذ سطرًا مع ذلك، 7.3 mm هنا. كل مجموع يدمج أربعة أعمدة في تسمية واحدة ملاصقة للحافة اليمنى. ونمط عنوان استمارة الطلب يحوّل الصفحة 4 إلى عمود واحد، فتمتد الشبكتان على عرض السطر الكامل البالغ 157 mm.
#5 · أبقِ الرسالة تحت الرسم
const ART = { w: 150, h: 104, y: 60 }; // mm: the cover painting, and its top on the page
const FRAME = 8; // mm: the cover's frame, in from the trim
const AIR = 10; // mm: at least this much between the painting and the letter
const SINK = Math.ceil((ART.y + ART.h + AIR - MARGIN.top) / (LEAD * 25.4 / 72)); // lines
const cover = { id: 'cover', span: 'page', footer: { elements: [] },
// The opener reserves down to the painting's foot; minHeight is a floor AIR lower, on the
// grid. The frame reaches the page's foot, so it stays out of that count: reserve: false
// (gotcha: opener-reserves-anchored).
advancedDesign: { enabled: true, minHeight: pt(SINK * LEAD), slot: { elements: [
{ kind: 'box', id: 'frame', reserve: false,
style: { borderColor: col('basil'), borderWidth: pt(1.2) },
placement: on('page', 'top-left', FRAME, FRAME,
{ width: mm(TRIM.w - 2 * FRAME), height: mm(TRIM.h - 2 * FRAME) }) },
text('publisher', '{title}', on('page', 'top', 0, 17), { ...caps(9.5), color: col('basil') }),
text('title', '{titleText}', on('page', 'top', 0, 23), { fontFamily: DISPLAY,
fontSize: pt(58), lineHeight: 1, color: col('tomato') }),
text('issue', '{subtitle}', on('page', 'top', 0, 49), { ...caps(8.5, 700), color: col('ink'),
box: { backgroundColor: col('sun'), padding: { top: mm(1.3), bottom: mm(1.1),
left: mm(4), right: mm(4) } } }),
{ kind: 'image', id: 'art', resourceId: 'cover-art',
placement: on('page', 'top', 0, ART.y, { width: mm(ART.w) }) },
] } },
};
يحجز الغلاف حتى أسفل رسمه، على بعد 164 mm من أعلى الصفحة، ومن دون minHeight كانت الرسالة ستبدأ عند أول خط شبكة تحته، ملاصقةً للتربة. وminHeight حدّ أدنى يقع تحته بقليل: يضيف SINK فراغًا قدره 10 mm تحت الرسم، ويقرّب العمق تحت الهامش العلوي صعودًا إلى عدد صحيح من الأسطر ذات 13 pt، أي 34 سطرًا، فيبدأ عمودا الرسالة كلاهما على الشبكة، على بعد 177.9 mm من أعلى الصفحة. وإطار الغلاف يبلغ أسفل الصفحة، فتُخرجه reserve: false من هذا الحساب.
الوصفة كاملة
// ═══ Postext Cookbook · Nº 036 · Mail-order catalogue with pictures in cells ═══════
// https://postext.dev/en/cookbook/seed-catalogue
// Code: MIT · Text: original (CC BY 4.0) · Pictures: diffusion models
// Fonts: Gelasio, Alfa Slab One, Cabin Condensed (SIL OFL 1.1) · Needs postext ≥ 1.25.0
// A fictional seed farm's spring list: a table read from TSV, a packet pictured in each row.
import {
buildDocumentWithFonts, prepareFonts, renderPageToCanvas, registerResourceImage, parseTSV,
mergeCells, setAlignment, setCellBackground, setCellContent, setCellImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'seed-catalogue';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { // eight named colours; every colour in the config links to one of them
ink: '#2d2620', paper: '#f0e2c4', // brown-black text on buff
cream: '#fcf7ea', tomato: '#c23b22', // cells to write in; the accent: bands, titles, NEW
basil: '#2f6b3b', sun: '#e8b53a', // rules, ORGANIC, the form's head; the cover's banner
rule: '#c7ae86', muted: '#6d5f50', // hairlines; running heads and notes
};
// col() links a colour to its palette entry; the hex is the value the entry holds.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries(palette)
.map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const TRIM = { w: 190, h: 250 }; // mm: a stapled mail-order booklet
const MARGIN = { top: 22, bottom: 20, inner: 18, outer: 15 }; // mm, mirrored: 157 mm wide
const LEAD = 13; // pt: the body leading, the grid the headings keep to
const TEXT = 'Gelasio', DISPLAY = 'Alfa Slab One', LABEL = 'Cabin Condensed';
const PACKET = 0.55; // the packet picture's share of its cell's inner width
const caps = (size, fontWeight = 600) => ({ fontFamily: LABEL, fontSize: pt(size), fontWeight,
letterSpacing: pt(size * 0.18), textTransform: 'uppercase' });
const on = (to, edge, x, y, size) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) },
...(size && { size }) });
const text = (id, content, placement, style) => ({ kind: 'text', id, content, placement,
overflow: 'wrap', ...style }); // a long line takes a second one, in the heads too
const chip = (id, size, ink, box) => ({ id, fontFamily: LABEL, bold: true, fontSize: em(size),
color: col(ink), borderRadius: pt(1.2), ...box });
const rule = (id, below, gap, thickness) => ({ kind: 'rule', id, direction: 'horizontal',
thickness: pt(thickness), color: col('basil'),
placement: { ...on(`#${below}`, 'below', 0, gap), size: { width: 'fill' } } });
// #region answer: a price list from TSV: a packet in each variety's cell, kinds merged down
const at = (row, c) => ({ row, col: c });
const slug = (name) => name.toLowerCase().replace(/\W+/g, '-'); // 'Gold Medal' → 'gold-medal'
function priceList(tsv) { // Kind · Variety · Description · Packet · Ounce, under one head row
let m = { ...parseTSV(tsv, { headerRows: 1 }), columnWidths: [20, 40, 63, 17, 17] }; // mm
for (const c of [0, 1]) m = setAlignment(m, at(0, c), 'center'); // each head over its column
يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)
تنويعات
#أبقِ ما يتسع فقط
مع overflow: 'clip' تتوقف القائمة بعد الأصناف الخمسة التي تتسع في الصفحة 2، والملاحظة تحتها، وليس في الصفحة 3 إلا ملاحظات حديقة التجارب، في عمودها الأول.
- overflow: 'split', continuedSuffix: '(continued)',
+ overflow: 'clip', continuedSuffix: '(continued)',#صغّر الأكياس
بنسبة 40% تنزل الصفوف إلى 29 mm، لكن صنفي الفاصولياء يتشاركان خلية مدمجة ويحتاجان معًا إلى 57 mm، أكثر من 44 mm الباقية في الصفحة 2. فتصعد ملاحظات حديقة التجارب إلى تلك المساحة، وليس في الصفحة 3 إلا بقية القائمة، والصفحة فارغة تحت 157 mm.
-const PACKET = 0.55; // the packet picture's share of its cell's inner width
+const PACKET = 0.4; // the packet picture's share of its cell's inner widthأخطاء شائعة
خطأ شائع
تحجز الافتتاحية ارتفاعًا يصل إلى أدنى عناصرها المثبّتة على الصفحة
تحجز الافتتاحية ذات التصميم المتقدّم ارتفاع أدنى عناصرها، وتُحتسب كذلك العناصر المثبّتة على الصفحة أو على النزف تحت العنوان، فالزخرفة في أسفل الصفحة تدفع النص إلى الصفحة التالية. أعطِ مثل هذا العنصر reserve: false (منذ postext 1.5): يُرسَم حيث ثُبّت ولا يحجز شيئًا. أما العناصر التي تتبع الشريط نفسه (المثبّتة على أسفله، أو التي ارتفاعها 'fill') فلا تحدّد ارتفاعه أبدًا. صفحات افتتاح مصمَّمة →
- المورد الذي لا يستشهد به أحد لا يوضع أبدًا. انزع
:refمن الرسالة فيبقى الكتالوج بلا قائمة أسعار. - في أعمدة عرضها 75 mm قد تترك خوارزمية Knuth–Plass سطرًا مضبوطًا تتمدد مسافاته أبعد من
maxWordSpacing؛ ويتيحbodyText.maxJustifyTrackingلمثل هذا السطر أن يأخذ قليلًا من تباعد الحروف بدل ذلك. وهنا أُعيدت صياغة الرسالة وملاحظات حديقة التجارب حتى صار أوسع سطر يمدّ مسافاته 1.33 ضعف عرضها العادي.
الحقوق
- الوصفة
- Ignacio Ferro
- النص
- نص أصلي, CC BY 4.0
- الصور
- The cover's sunflower and tomato plant, a painting · Generated With Diffusion Models · أصلي
- The Brandywine seed packet · Generated With Diffusion Models · أصلي
- The Cherokee Purple seed packet · Generated With Diffusion Models · أصلي
- The Gold Medal seed packet · Generated With Diffusion Models · أصلي
- The Amish Paste seed packet · Generated With Diffusion Models · أصلي
- The Jimmy Nardello seed packet · Generated With Diffusion Models · أصلي
- The Kentucky Wonder seed packet · Generated With Diffusion Models · أصلي
- The Dragon Tongue seed packet · Generated With Diffusion Models · أصلي
- The Black Beauty seed packet · Generated With Diffusion Models · أصلي
- The Waltham Butternut seed packet · Generated With Diffusion Models · أصلي
- الخطوط
- Gelasio (SIL OFL 1.1) · Alfa Slab One (SIL OFL 1.1) · Cabin Condensed (SIL OFL 1.1)
- الشيفرة
- MIT، مثل Postext
حرّر هذا الشرح ↗ (يفتح في تبويب جديد)مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)


