跳到主要内容
食谱编号160

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

穿过一串框排下去的杂志专题

一个跨页的模板页:两栏用 next 串接,再通过 overflow.continueIn 接续到新增的页上,绕开一段引语和一只抠图蜂笼。

本页内容
输出
Canvas · PDF
难度
高级
Postext
已用Postext 1.65.0测试
需要≥ 1.65.0 · postext-pdf ≥ 1.65.0
许可证
更新于2026年10月31日
代码MIT · 文本CC BY 4.0

页码46–47 · 第1–2页,共4页

  • 西班牙文样例:尚无中文版本
  • 成品尺寸225 × 297 mm
  • 1栏
  • Literata 9.8/13.6
  • Fraunces
  • Instrument Sans
  • 4页
  • 难度
  • Postext 1.65.0
  • 排版用时162 ms
  • 210行代码

简单来说

一篇四页的杂志文章按模板排出:文字自己从一栏流到下一栏,再流到新的一页,并绕开一段引语和一张照片的轮廓。

成品一览

虚构的城市生活季刊《Patio》第 46 至 49 页。专题写一位退休的排字工:她在自己干了三十年的印刷厂楼顶养着十四箱蜜蜂。开篇跨页的左页是照片,标题压在楼顶的碎石上,天空里放一个浅色底的数字框。右页是导语和前两栏,一段引语跨在栏间距上,旁边立着一只抠掉背景的草编蜂笼,第二栏的行顺着笼顶的弧线排。之后文章需要几页就占几页,每页三栏,排到哪里就在哪里结束。西班牙语、英语和德语版是同一个模板换了文字,德语的长复合词要穿过 60 毫米宽的栏。

这道食谱解答

  • 怎样让一篇杂志文章在几页之间顺着相连的框接续排下去?
  • 怎样按栏目排杂志,每篇文章从跨页开始,主图放在对页?
  • Postext能排三栏或更多栏,或者让文字绕图排吗?

简短回答

script.js · 第61–89行在完整代码中
const opening = {
  id: 'apertura',
  spread: true,
  header: false,
  frames: [
    { name: 'titulo', takes: 'h1', layer: 2, width: mm(150),
      placement: at('container', 'bottom-left', 4, -14) },
    { name: 'datos', style: 'datos', layer: 2, width: mm(64),
      placement: at('container', 'top-left', 4, 6) },
    { name: 'entradilla', width: mm(2 * COLUMN + GAP),
      placement: at('container', 'top-left', RECTO) },
    // The story names no slot, so it goes to the flow frame, then on down the chain.
    { name: 'col-1', flow: true, next: 'col-2', width: mm(COLUMN), height: 'fill',
      placement: at('#entradilla', 'below', 0, 7) },
    // What the last column cannot hold goes on to a page added after the spread.
    { name: 'col-2', width: mm(COLUMN), height: 'fill',
      placement: at('#col-1', 'right-of', GAP),
      overflow: { continueIn: 'template:seguido' } },
    ...pushers,
  ],
  decoration: { elements: [
    { kind: 'image', id: 'foto', resourceId: '{attr.foto}',
      fit: 'cover',
      placement: { ...at('bleed', 'top-left'), size: { width: mm(W), height: 'fill' } } },
    { kind: 'text', id: 'seccion', content: '{attr.seccion}', fontFamily: SANS, fontSize: pt(9),
      fontWeight: 700, letterSpacing: pt(2), textTransform: 'uppercase', color: col('paper'),
      placement: at('#titulo', 'above', 0, -3) },
  ] },
};

用料

类型
Literata, Fraunces, Instrument Sans(SIL OFL 1.1)
素材
  • rooftop-1400.jpg
  • skep-720.png
  • Painted hives on a factory roof at sunrise (the opening spread) (Generated With Diffusion Models, 原创)
  • A straw bee skep on a transparent ground (the cut-out the text runs round) (Generated With Diffusion Models, 原创)

做法

#1 · 一个模板,一篇文章

代码就是上面的简短回答。整篇专题是一个 ::::page{template="apertura" spread} 页面块:标题进入 takes: 'h1' 的框,数字和导语进入各自的槽位,其余没有指定槽位的内容都进入流文框 col-1。col-1 排满后,文字接着进入 col-2,按它的宽度重新断行;col-2 放不下的部分,在截断处印上 Continúa 之后,接续到跨页后面新增的一页(overflow.continueIn: 'template:seguido')。文字既不指定栏,也不指定页:删掉一段,后面的每一行都往回移。

#2 · 文章新增的页

script.js · 第93–105行在完整代码中
// The third column continues into this same template: the story goes on in the frame its
// chain starts in, so every added page fills all three columns.
const seguido = {
  id: 'seguido',
  frames: [
    { name: 'seguido-1', flow: true, next: 'seguido-2', height: 'fill', width: mm(60.3) },
    { name: 'seguido-2', next: 'seguido-3', height: 'fill', width: mm(60.3),
      placement: at('#seguido-1', 'right-of', 5) },
    { name: 'seguido-3', height: 'fill', width: mm(60.3),
      placement: at('#seguido-2', 'right-of', 5),
      overflow: { continueIn: 'template:seguido' } },
  ],
};

每个新增页有三个串接的栏,各宽 60.3 毫米,所有新增页共用一个模板。第三栏接续到这个模板本身,文章接在它的串接起点 seguido-1 里:不论要加几页,每页都排满三栏。字号也不必另行固定:能接续到别页的框,会先接续,再考虑把文字缩小,所以多出五行的文章会得到一页新页,而不是在最后一页缩到 92.5%。

#3 · 两个推开栏文的框

script.js · 第50–57行在完整代码中
const pushers = [
  // The pull quote straddles the gutter: each column loses the side it covers.
  { name: 'cita', style: 'cita', exclude: 'push', width: mm(62),
    placement: at('#entradilla', 'below', COLUMN - 27.5, 82) },
  // The skep's frame pushes with the shape of its picture, read from the PNG's alpha.
  { name: 'recorte', exclude: 'push', wrap: 'contour', layer: 2, width: mm(58),
    placement: at('container', 'bottom-right', 9, -8) },
];

这两个框都不属于文章,只推开它们压住的栏里的行。引语锚定在导语下方 82 毫米处,跨在栏间距上,所以第一栏让出右侧,第二栏让出左侧。蜂笼的框设了 wrap: 'contour':它旁边的每一行,按图片在该行高度上的宽度再加 2.5 毫米间距缩短,于是第二栏顺着笼顶排,到笼底以下又恢复全宽。

#4 · 跟着图片走的轮廓

script.js · 第300–316行在完整代码中
const photo = { id: 'azotea', typeId: 'foto', kind: 'bitmap', createdAt: 0, updatedAt: 0,
  caption: '', altText: t({
    es: 'Seis colmenas de colores en la azotea de una fábrica, con la ciudad al amanecer',
    en: 'Six painted hives on a factory roof, with the city behind them at sunrise',
    de: 'Sechs bunte Bienenkästen auf einem Fabrikdach, dahinter die Stadt im Morgenlicht' }),
  bitmap: { fileId: 'rooftop-1400.jpg', format: 'jpeg', width: 1400, height: 1848 } };
let skep = { id: 'cesto', typeId: 'foto', kind: 'bitmap', createdAt: 0, updatedAt: 0,
  caption: '', altText: t({ es: 'Un cesto de paja para abejas', en: 'A straw bee skep',
    de: 'Ein Bienenkorb aus Stroh' }),
  contour: { threshold: 0.5, margin: mm(2.5) },
  bitmap: { fileId: 'skep-720.png', format: 'png', width: 720, height: 828 } };
await loadImage('rooftop-1400.jpg', asset('rooftop-1400.jpg'));
await loadImage('skep-720.png', asset('skep-720.png'));
// The layout reads pictures by size, never by pixels: the outline travels as a trace.
const trace = await traceResourceContour(skep, imageBytes('skep-720.png'), 'image/png');
skep = withContourTrace(skep, trace);
const resources = [photo, skep];

排版只按尺寸读取图片,从不读像素,所以轮廓用 traceResourceContour 从 PNG 的 Alpha 通道里取一次,作为 contour.traced 跟着资源走。蜂笼是一张 720 像素、200 色、透明底的 PNG(225 KB)。左页的照片是装饰图片 resourceId: '{attr.foto}':用哪张照片由页面块决定,放在哪里由模板决定。 它带有 fit: 'cover':照片的比例不论如何,都会铺满左页,超出框的部分被裁掉。

#5 · 从围栏读取的书眉

script.js · 第109–120行在完整代码中
const head = (id, content, parity, edge, x, extra = {}) => ({
  kind: 'text', id, content, parity, fontFamily: SANS, fontSize: pt(7.5), fontWeight: 600,
  letterSpacing: pt(1.2), textTransform: 'uppercase', color: col('muted'),
  placement: at('page', edge, x, 11), ...extra,
});
const folio = { fontWeight: 700, color: col('honey') };
const header = { elements: [
  head('verso-folio', '{pageNumber}', 'even', 'top-left', OUT, folio),
  head('verso-title', '{title}', 'even', 'top-left', OUT + 9),
  head('recto-title', '{attr.seccion}', 'odd', 'top-right', -(OUT + 9)),
  head('recto-folio', '{pageNumber}', 'odd', 'top-right', -OUT, folio),
] };

开篇跨页不印书眉(header: false);新增的页在左页印杂志名,在右页印栏目名。栏目名来自页面块上的 seccion="Ciudad",{attr.seccion} 在文章新增的页上读到的值和在跨页上一样。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 160 · A magazine feature threaded through frames ═════
// https://postext.dev/en/cookbook/magazine-threaded-frames
// Code: MIT · Text: original (CC BY 4.0) · Pictures: Generated With Diffusion Models
// Fonts: Literata, Fraunces, Instrument Sans (SIL OFL 1.1) · Needs postext ≥ 1.65.0
//
// A six-page feature of an invented city magazine, set as one composed page: an opening
// spread whose frames are drawn in the config, and pages the text adds as it runs on.
// Every word, the photo's id and the section name are in content.<lang>.md.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
  traceResourceContour, withContourTrace,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';

const LANG = 'es'; // @lang: the language of the sample document ('es' | 'en' | 'de')
const RECIPE = 'magazine-threaded-frames';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: honey on warm paper, every colour linked by id
const palette = {
  ink: '#211c18', // text
  honey: '#a65a12', // the accent: kickers, rules, the drop cap, the pull quote
  tint: '#f5ecdc', // the fact box
  rule: '#d8c6a6', // hairlines
  muted: '#6b6158', // running heads, credits
  paper: '#ffffff',
  shade: '#1a1612', // the plate under the headline on the photo
};
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' } })),
  { id: 'main-color', name: 'honey (defaults)', value: { hex: palette.honey, model: 'hex' } },
];
// #endregion

const SERIF = 'Literata';
const DISPLAY = 'Fraunces';
const SANS = 'Instrument Sans';
const W = 225; // trim width in mm; the spread's sheet is twice as wide
const IN = 16; // inner margin
const OUT = 18; // outer margin
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
// The spread's content area runs from the verso's outer margin to the recto's: a frame
// on the recto starts RECTO mm in from its left edge.
const RECTO = W - OUT + IN;
const COLUMN = 92; // the two columns of the recto
const GAP = 7;

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

变化

#按矩形绕排蜂笼

去掉 wrap: 'contour',框就按它的矩形推开文字,笼顶旁边的行停在一条直边上。

-  { name: 'recorte', exclude: 'push', wrap: 'contour', layer: 2, width: mm(58),
+  { name: 'recorte', exclude: 'push', layer: 2, width: mm(58),

#去掉接续标记

设 mark: false,截断的片段排到最后一行就结束,不印 Continúa,这一栏能多放一行。

-      overflow: { continueIn: 'template:seguido' } },
+      overflow: { continueIn: 'template:seguido', mark: false } },

常见问题

  • 模板送进独立框的标题,不会让文字框里的段落首字下沉。专题的第一段包在 :::paragraphs{style="inicio"} 里,dropCap 写在这个样式上。

致谢

文本
原创文字, CC BY 4.0
图片
  • Painted hives on a factory roof at sunrise (the opening spread) · Generated With Diffusion Models · 原创
  • A straw bee skep on a transparent ground (the cut-out the text runs round) · Generated With Diffusion Models · 原创
字体
Literata (SIL OFL 1.1) · Fraunces (SIL OFL 1.1) · Instrument Sans (SIL OFL 1.1)
沙盒PDF