跳到主要内容
食谱编号23

排版食谱 · 第9章 · 完整出版物

杂志封面与分栏目目录

照片封面上的封面标题挂在刊名之下;自动生成的目录为每个栏目排一行彩色条。每个栏目都是一个不开新页的篇。

  • 英文样例:尚无中文版本
  • 成品尺寸230 × 300 mm
  • 2栏, 栏间距6 mm
  • Spectral 9.5/13.5
  • Bodoni Moda
  • Jost
  • 6页
  • 难度
  • Postext 1.57.1
  • 排版用时194 ms
  • 249行代码

简单来说

一本美食与农业杂志的封面和前几页,封面是一张照片,还有目录页。示例演示怎样给每个栏目定一个颜色,并让它贯穿该栏目的各页。

成品一览

虚构的饮食与土地季刊《FALLOW》一期中的六页,页面尺寸230 × 300 mm。封面上一幅托斯卡纳山谷出血排到页边,上方是118 pt的Bodoni刊名;三条封面标题放在一块纸色底板上,每条的眉题取其栏目的颜色,角落里是价格和条形码。第2页是自动生成的目录:每个栏目一条彩色色标,下面是文章标题、页码和导语。右栏是编者按、撰稿人和版权栏。后面的栏目依次为赤陶色、橄榄绿和酒红色。每篇文章都以一幅横贯页面上部的出血图片开篇,一块栏目颜色的底板升入图片中;文章的页码色标、项目符号和框也取这种颜色。颜色由每篇文章上方的:::part围栏设定,这个围栏不开篇名页。

这道食谱解答

  • 怎样制作封面、简扉页、扉页和版权页?
  • 怎样添加自动更新的目录(前导符、页码、作者、篇名行)?
  • 怎样把书分成若干篇或部分,每篇有自己的颜色和隔页?
  • 怎样给每章不同的照片、颜色或章首页样式?

简短回答

script.js · 第39–74行在完整代码中
const MASTHEAD = TRIM.width - MARGIN.inner - MARGIN.outer; // the word spans the text block
const PANEL = 84; // mm: the cover lines' panel, a column of paper over the photograph
const SEAM = 0.3; // mm: each box overlaps the one above, so no hairline of photo shows
// A cover line: a kicker in its section's colour over a line in Bodoni, on paper boxes of one
// width. Chained with 'below' they read as one panel, and a longer line pushes the rest down.
const sheet = (top, bottom) => ({ backgroundColor: col('paper'),
  padding: { top: mm(top), right: mm(5), bottom: mm(bottom), left: mm(5) } });
const small = { ...label, fontSize: pt(8), letterSpacing: pt(1.6), color: col('ink') };
const coverLine = (n, colour, above = n === 1 ? '#masthead' : `#line${n - 1}`) => [
  text(`kicker${n}`, `{attr.kicker${n}}`, { ...small, color: col(colour),
    box: sheet(n === 1 ? 5 : 4, 1.5) },
  { ...at(above, 'below', 0, n === 1 ? 8 : -SEAM), size: { width: mm(PANEL) } }),
  text(`line${n}`, `{attr.line${n}}`, { ...bodoni, italic: true, fontSize: pt(15),
    lineHeight: 1.12, color: col('ink'), box: sheet(0, n === 3 ? 5 : 0) }, // line 3 ends the panel
  { ...at(`#kicker${n}`, 'below', 0, -SEAM), size: { width: mm(PANEL) } }),
];
const cover = { enabled: true, slot: { elements: [
  { kind: 'image', id: 'photo', resourceId: 'cover', // the JPEG is cropped to the trim, 23 : 30
    placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: 'fill' } } },
  text('strap', '{subtitle}', small, at('page', 'top-left', MARGIN.inner, 12)), // a recto
  text('issue', '{attr.issue}', { ...small, align: 'right' },
    at('page', 'top-right', -MARGIN.outer, 12)),
  text('masthead', '{titleText}', { ...bodoni, fontWeight: 900, fontSize: pt(118),
    lineHeight: 0.86, // set tight: the masthead is capitals, with no descenders
    letterSpacing: pt(1), textTransform: 'uppercase', align: 'center', color: col('ink') },
  { ...at('#strap', 'below', 0, 6), size: { width: mm(MASTHEAD) } }),
  ...coverLine(1, 'olive'), ...coverLine(2, 'terracotta'), ...coverLine(3, 'wine'),
  // The price and a made-up barcode sit in the corner, anchored to the page, not the words.
  text('price', '{attr.price}', { ...small, fontSize: pt(7), box: sheet(1, 1.5) },
    { ...at('page', 'bottom-right', -MARGIN.outer, -12), size: { width: mm(32) } }),
  { kind: 'image', id: 'barcode', resourceId: 'barcode',
    placement: { ...at('#price', 'above', 0, SEAM), size: { width: mm(32) } } },
] } };
// hook-up: headingStyles gets { id: 'cover', numbered: false, toc: false, advancedDesign: cover,
// footer: { elements: [] } }, with no folio; the Markdown's first line is
// # Fallow {style="cover" issue="…" price="…" kicker1="…" line1="…" … kicker3="…" line3="…"}

用料

类型
Spectral, Bodoni Moda, Jost(SIL OFL 1.1)
素材
  • castellina-cover-1150.jpg
  • castellina-farm-1530.jpg
  • fields-1610.jpg
  • flasks-1920.jpg
  • harvest-1840.jpg
  • Castellina in Chianti (the cover and its copy in the contents) (Rowan Heuvel, CC0 1.0)
  • Castellina in Chianti, a detail (the feature's photograph) (Rowan Heuvel, CC0 1.0)
  • Plants in beakers (the Field notes opener) (chuttersnap, CC0 1.0)
  • Harvesting the wheat crop (the Kitchen opener) (meriç tuna, CC0 1.0)
  • Fields from above near Castellina in Chianti (the feature's opener) (Generated With Diffusion Models, 原创)
  • The cover's barcode, drawn in code (Ignacio Ferro, MIT)

做法

#1 · 让封面从刊名往下挂

代码见上面的简短回答。只有照片、页头的两行文字和价格锚定在页面上。其余元素都锚定在另一个元素上(元素定位):刊名在标语之下,第一条眉题在刊名下方8 mm,之后每条标题在其眉题之下、每条眉题在前一条标题之下。这样,封面标题变长或刊名变大时,会把下面的内容往下推,而不是压在上面。每条眉题和每条标题各有一个84 mm宽的纸色框,六个框叠在一起就是底板,随文字多少而伸缩。第一个框之后的每个框都与上一个重叠0.3 mm(SEAM),条形码与价格框也同样重叠,因为在Canvas上两块刚好相接的填充色之间会漏出一条细细的照片。杂志没有半书名页和书名页:封面承载刊名,目录页承载期号、季节和版权栏。图书的前置部分见前置部分用罗马数字页码,正文从第1页起。

#2 · 把每个栏目设为不开新页的篇

script.js · 第78–87行在完整代码中
const parts = { page: false }; // a :::part now only sets the section's title and palette
const story = (id, picture) => ({ id, numbered: false, advancedDesign: opener(picture) });
const headingStyles = () => [
  { id: 'cover', numbered: false, toc: false, advancedDesign: cover,
    footer: { elements: [] } }, // no folio on the cover (the header is empty everywhere)
  { id: 'contents', numbered: false, toc: false, advancedDesign: contentsOpener,
    footer: folioLine('{title}', '{publishDate}') }, // no section yet: the issue instead
  // One opener for every story; the style names its picture, the part its colour.
  story('grain', 'flasks'), story('rest', 'fields'), story('bread', 'harvest'),
];

设置parts.page: false后,:::part{title="Features" palette="band=#5d6a2b"}这样的围栏不开篇名页,只从下一个块起设定栏目的标题和调色板(:::part容器)。每篇文章的H1使用带numbered: false的标题样式,所以目录列出它时不带编号。样式决定首页的图片,篇提供颜色。

#3 · 把所有栏目颜色链接到同一个条目

script.js · 第14–27行在完整代码中
const palette = {
  ink: '#1c1a16', // text: a warm near-black
  paper: '#fbf8f1', // the page, and type set on colour
  band: '#8b6a3e', // the house earth; each :::part fence brings its own 'band'
  muted: '#6b6358', // credits and the standfirsts in the contents
  olive: '#5d6a2b', terracotta: '#a3472a', wine: '#7a2c3a', // as in the :::part fences: edit both
};
// A part overrides by id: col() writes the id beside the hex, and the designs follow it.
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' } })),
  // The engine's defaults link to 'main-color': point it at the ink, so nothing prints blue.
  { id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];

篇按id覆盖调色板条目,因此随栏目变化的一切都链接到band:首页的底板、页码色标、项目符号和列表编号、引文框,以及资料框的色条和标题。在正文中,覆盖按值进行:凡是十六进制值等于band基准值(#8b6a3e)的颜色,都换成栏目的颜色,所以其他条目都不用这个值。设计元素则相反:篇的覆盖通过paletteId作用到它们,所以col()把id写在十六进制值旁边。

#4 · 让目录自己分组

script.js · 第91–124行在完整代码中
const mid = at('container', 'left', 0, -1); // the row's middle, 1 mm up: air above the title
const contents = { // passed to the config as `toc`
  levels: [{ level: 1, fontFamily: 'Bodoni Moda', fontSize: pt(17), fontWeight: 600,
    marginBottom: pt(2 * LEAD) }], // in ink, on the body's 13.5 pt leading
  pageNumber: { fontSize: pt(26), width: mm(14) }, // in the levels' Bodoni
  leader: { enabled: false }, subtitle: { enabled: true, attr: 'standfirst', // in italic
    fontFamily: 'Spectral', fontSize: pt(10), color: col('muted') },
  // A part row is a design as wide as the column; its 'band' takes the part's palette. No
  // {pageNumber} in it: each story under the tab prints its own page.
  parts: { height: pt(2 * LEAD), design: { elements: [ // two grid lines (the default: 2 em)
    { kind: 'rule', id: 'line', thickness: pt(0.75), color: col('band'), // behind the tab
      placement: { ...mid, size: { width: 'fill' } } },
    text('tab', '{titleText}', { ...label, fontSize: pt(8), letterSpacing: pt(1.6),
      color: col('paper'), box: { backgroundColor: col('band'),
        padding: { top: mm(1.2), right: mm(2.4), bottom: mm(1.2), left: mm(2.4) } } },
    mid),
  ] } },
};
// The colophon closes the contents page; the Markdown calls it with :::paragraphs.
const colophon = { id: 'colophon', fontFamily: 'Jost', fontSize: pt(7), lineHeight: pt(10),
  color: col('muted'), textAlign: 'left', firstLineIndent: pt(0), marginTop: pt(LEAD) };
const air = { padding: { bottom: mm(9) } }; // empty padding counts: the columns start lower
const contentsOpener = { enabled: true, slot: { elements: [
  { kind: 'rule', id: 'rule', thickness: pt(1), color: col('ink'),
    placement: { ...at('container', 'top-left'), size: { width: 'fill' } } },
  text('kicker', '{titleText}', { ...label, fontSize: pt(9), letterSpacing: pt(1.8),
    color: col('band') }, at('#rule', 'below', 0, 5)),
  text('issue', '{attr.issue}', { ...bodoni, italic: true, fontSize: pt(44), lineHeight: 1.05,
    color: col('ink') }, at('#kicker', 'below', 0, 2)),
  text('strap', '{subtitle}', { fontFamily: 'Spectral', italic: true, fontSize: pt(11),
    color: col('muted'), align: 'left' }, at('#issue', 'below', 0, 1.5)),
  text('number', '{attr.number}', { ...bodoni, fontWeight: 900, fontSize: pt(160), lineHeight: 1,
    align: 'right', color: col('band'), box: air }, at('container', 'top-right', 0, 4)),
] } };

:::toc列出各篇文章,并为每个:::part排一行,版式取自toc.parts.design,颜色用该篇的调色板(目录),所以一种行设计印出三种颜色的三个色标。细线和色标都挂在mid上,即这一行的中线再上移1 mm,使色标不碰到下方的标题。关闭前导符后,标题和页码(3、4、6)之间不连任何东西;subtitle.attr把首页标题的standfirst属性用斜体印在标题下方。右栏末尾的版权栏是一个段落样式,Jost 7 pt、颜色muted,Markdown用:::paragraphs{style="colophon"}套用它。

#5 · 给每篇文章同样的首页

script.js · 第128–152行在完整代码中
const PHOTO = 150; // mm from the top edge to the foot of the picture
const FOOT = PHOTO - MARGIN.top; // the same foot from the container, which starts at the margin
const LIFT = 34; // mm: how far the panel rises into the picture
const WIDE = 136; // mm: the panel's width
const panel = (top, bottom) => ({ backgroundColor: col('band'),
  padding: { top: mm(top), right: mm(6), bottom: mm(bottom), left: mm(6) } });
const below = (id) => ({ ...at(`#${id}`, 'below', 0, -SEAM), size: { width: mm(WIDE) } });
const opener = (resourceId) => ({ enabled: true, slot: { elements: [
  { kind: 'image', id: 'picture', resourceId, // fitted, never cropped: each file is 230 : 150
    placement: { ...at('bleed', 'top-left'), size: { width: 'fill', height: mm(PHOTO) } } },
  text('credit', '{attr.credit}', { ...small, fontSize: pt(6.5), color: col('muted'),
    letterSpacing: pt(0.6), align: 'right' }, at('container', 'top-right', 0, FOOT + 2)),
  text('section', '{partTitle}', { ...label, fontSize: pt(8.5), letterSpacing: pt(1.7),
    color: col('paper'), box: panel(6, 2) }, { ...at('container', 'top-left', 0, FOOT - LIFT),
    size: { width: mm(WIDE) } }),
  text('title', '{titleText}', { ...bodoni, fontWeight: 700, fontSize: pt(32), lineHeight: 1.02,
    color: col('paper'), box: panel(0, 3) }, below('section')),
  text('standfirst', '{attr.standfirst}', { fontFamily: 'Spectral', italic: true,
    fontSize: pt(11.5), lineHeight: 1.35, overflow: 'wrap', align: 'left',
    color: col('paper'), box: panel(0, 6) }, below('title')),
  // The panel and the byline reach below the picture's foot, so they set where the story
  // starts; the byline's empty padding keeps the first line 5 mm under it.
  text('byline', '{attr.byline}', { ...small, fontSize: pt(7.5), letterSpacing: pt(1.3),
    box: { padding: { top: mm(4), bottom: mm(5) } } }, at('#standfirst', 'below')),
] } });

图片从页面顶边出血,向下延伸150 mm。一块band颜色的底板升入图片底部34 mm。底板由三个136 mm宽的文本框组成,每个都用below接在前一个之下,分别放{partTitle}给出的栏目名、标题和导语。底板和署名都伸到图片底边以下,所以正文从最低的元素下方开始,也就是署名;署名底部5 mm的空白内边距让第一行正文至少离它这么远。

#6 · 在页码处写出栏目名

script.js · 第156–171行在完整代码中
const TAB = 6.5; // mm: the tab's side; the words beside it take its height and centre on it
const folioLine = (first, second) => ({ elements: [['even', 'left', 1], ['odd', 'right', -1]]
  .flatMap(([parity, side, s]) => {
    const inward = s > 0 ? 'right-of' : 'left-of'; // from the outer edge towards the gutter
    const beside = (id, content, style, to, gap) => text(id, content, { ...style, align: side },
      { ...at(to, inward, s * gap), size: { height: mm(TAB) } }); // text centres vertically
    return [
      text(`tab-${parity}`, '{pageNumber}', { ...label, fontSize: pt(8), color: col('paper'),
        align: 'center', box: { backgroundColor: col('band') } },
      { ...at('page', `bottom-${side}`, s * MARGIN.outer, -11),
        size: { width: mm(TAB), height: mm(TAB) } }),
      beside(`first-${parity}`, first, { ...small, color: col('band') }, `#tab-${parity}`, 3),
      beside(`second-${parity}`, second, { fontFamily: 'Spectral', italic: true,
        fontSize: pt(8), color: col('muted') }, `#first-${parity}`, 2.5),
    ].map((element) => ({ ...element, parity })); // no pages filter: openers get folios too
  }) });

页码放在外侧页脚一个6.5 mm见方的band色块里。栏目名锚定在它旁边、朝向订口一侧,文章标题又在栏目名旁边;三个框都高6.5 mm,文字垂直居中,所以共用一条中线。杂志在首页上也印页码,因此页脚不设pages筛选。封面的标题样式清空页脚;目录的样式在原来放栏目和文章的位置印出杂志名和本期季节({title}和{publishDate})。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 023 · Magazine cover and sectioned contents ═══════════════
// https://postext.dev/en/cookbook/magazine-cover-and-contents
// Code: MIT · Text: original (CC BY 4.0) · Photos: R. Heuvel, chuttersnap, m. tuna (CC0), diffusion
// Fonts: Spectral, Bodoni Moda, Jost (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'magazine-cover-and-contents';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one house colour, 'band', that every section overrides
const palette = {
  ink: '#1c1a16', // text: a warm near-black
  paper: '#fbf8f1', // the page, and type set on colour
  band: '#8b6a3e', // the house earth; each :::part fence brings its own 'band'
  muted: '#6b6358', // credits and the standfirsts in the contents
  olive: '#5d6a2b', terracotta: '#a3472a', wine: '#7a2c3a', // as in the :::part fences: edit both
};
// A part overrides by id: col() writes the id beside the hex, and the designs follow it.
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' } })),
  // The engine's defaults link to 'main-color': point it at the ink, so nothing prints blue.
  { id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion
const TRIM = { width: 230, height: 300 }; // an independent-magazine trim, in mm
const MARGIN = { top: 22, bottom: 20, inner: 16, outer: 14 }; // mirrored
const LEAD = 13.5; // body leading in pt: the baseline grid
const caps = { fontFamily: 'Jost', fontWeight: 600, textTransform: 'uppercase' }; // the label face
const label = { ...caps, align: 'left' }; // design text is centred by default
const bodoni = { fontFamily: 'Bodoni Moda', overflow: 'wrap', align: 'left' };
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const text = (id, content, look, placement) => ({ kind: 'text', id, content, placement, ...look });

// #region answer: the cover, one design slot whose words hang from each other
const MASTHEAD = TRIM.width - MARGIN.inner - MARGIN.outer; // the word spans the text block
const PANEL = 84; // mm: the cover lines' panel, a column of paper over the photograph
const SEAM = 0.3; // mm: each box overlaps the one above, so no hairline of photo shows
// A cover line: a kicker in its section's colour over a line in Bodoni, on paper boxes of one
// width. Chained with 'below' they read as one panel, and a longer line pushes the rest down.
const sheet = (top, bottom) => ({ backgroundColor: col('paper'),
  padding: { top: mm(top), right: mm(5), bottom: mm(bottom), left: mm(5) } });
const small = { ...label, fontSize: pt(8), letterSpacing: pt(1.6), color: col('ink') };
const coverLine = (n, colour, above = n === 1 ? '#masthead' : `#line${n - 1}`) => [
  text(`kicker${n}`, `{attr.kicker${n}}`, { ...small, color: col(colour),

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

变化

#刊名用杂志的主色

刊名改用目录页上大号14的土棕色。

-    textTransform: 'uppercase', align: 'center', color: col('ink') },
+    textTransform: 'uppercase', align: 'center', color: col('band') },

#每个栏目以分隔页开篇

如果要让每个篇有自己的页面,并在目录的每个篇名行中印出页码,见用一个属性给各篇配色。

常见问题

易错点

'top'浮动体默认排在引用页的下一页,除非允许它置于引用页顶

默认情况下浮动体不会排在自己的引用之前,所以在第N页引用的整页宽'top'浮动体会出现在第N+1页的顶部。在资源或其类型的defaultPlacement上设置placement.citingPage: true(或者对全书设置layout.floatsAtCitingPage,自postext 1.25起),它就改为置于第N页顶部,引用处之上的文字移到它下方,前提是它不超过layout.maxTopFraction且引用行仍留在该页。它不会置于章首页或强制分页之后的页面顶部:那时仍排在下一页,而'auto'或'bottom'可以占用引用页的底部。 图的放置 →

易错点

位图的印刷尺寸取自分辨率:声明分辨率,不要换算印刷像素

没有分辨率的位图按文档dpi以一个像素对应一个排版像素放置,所以2400 px的照片在150 dpi的页面上宽406 mm。声明文件的实际像素,并给图片设分辨率(bitmap.resolution: 300),或为所有位图设置layout.bitmapResolution:一个ppi值,或用'file'读取文件标明的分辨率。栏宽仍会限制图片。 作为资源的图和表 →

  • 图片元素把图片缩放到框内,从不裁切。先把每张JPEG裁成框的比例,封面为23 : 30,文章首页为230 × 150 mm,否则图片会缩小,边上留出白条。
  • 在正文中,篇会给所有十六进制值等于band基准值的颜色换色,不管它是否链接到band。这个值只留给应随栏目变化的内容。
  • 两种语言的文章都做过字数调整:西班牙语版Field notes删短了几句,以便排在一页之内;英文专题有一句删了三个词,使第4页两栏齐底。修改之后,检查没有哪篇文章多出几行溢到新的一页,并且除每篇文章的最后一页外,每页各栏都齐底。

致谢

文本
原创文字, CC BY 4.0
图片
  • Castellina in Chianti (the cover and its copy in the contents) · Rowan Heuvel · CC0 1.0
  • Castellina in Chianti, a detail (the feature's photograph) · Rowan Heuvel · CC0 1.0
  • Plants in beakers (the Field notes opener) · chuttersnap · CC0 1.0
  • Harvesting the wheat crop (the Kitchen opener) · meriç tuna · CC0 1.0
  • Fields from above near Castellina in Chianti (the feature's opener) · Generated With Diffusion Models · 原创
  • The cover's barcode, drawn in code · Ignacio Ferro · MIT
字体
Spectral (SIL OFL 1.1) · Bodoni Moda (SIL OFL 1.1) · Jost (SIL OFL 1.1)
沙盒