简单来说
一张学术会议用的大海报,讲行道树和街道降温。示例演示怎样在一张很大的页面上分栏排放文字框和图表。
成品一览
一张会议海报,内容是一项虚构的研究:行道树与人行道温度。整张海报排在一个600 × 800 mm的页面上。绿色色带上是会议名称、110 pt Bitter标题、带单位标记的作者和地理学院的标志。两栏摘要下方,一个:::columns分栏组横跨两个正文栏,把六块面板排成三栏,每块面板是一个框,上方有一条6 pt的色条。中间一栏以150 pt的橙色−4.2 °C开头,接着是按街区和时段显示气温的热力图,配彩色色块图例,然后是一张路面材料柱状图。一条带底色的关键词标签长条位于下页边距上。同一文件还能排出西班牙语版本,CodePen示例还提供1,701 × 2,268 px的PNG页面。
这道食谱解答
- 怎样在页面中间排一个横跨两栏的框,比如三格并列的“数字一览”面板?
- 怎样在框里分两栏(文字栏旁边是图栏)?
- 怎样在正文、题注或表注里加入色块图例?
简短回答
// The body text runs in two columns and the panels in three: a :::columns group in the
// text, and span="page" lays it across both body columns, the gutter apart.
// :::columns{count=3 breaks="3,4" span="page" marginBottom="0.75em"}
// ← panel 3 opens column 2, panel 4 column 3
// :::callout{type="panel" title="Introduction"} ← each panel is a box in the group
// …
// ::: ← closes the panel; then the other panels
// ::: ← closes the columns group
// marginBottom sets the space under the group: without it the group is followed by a
// line of the summary's paragraph spacing, 38 pt.
// A box in a group takes the width of its column. Its one device is a 6 pt stripe along
// the top.
const panel = { id: 'panel', backgroundEnabled: false,
stripe: { enabled: true, side: 'top', width: pt(6), color: col('canopy') },
padding: { top: mm(5), right: pt(0), bottom: pt(0), left: pt(0) },
titleStyle: { fontFamily: 'Saira Condensed', fontSize: pt(40), fontWeight: 700,
textTransform: 'uppercase', letterSpacing: pt(4), color: col('canopy'), gap: mm(4) },
body: { fontSize: pt(22), lineHeight: pt(30) }, // the rest follows bodyText
marginTop: mm(18) };
const results = { ...panel, id: 'results', // the finding: the same panel, striped in heat
stripe: { ...panel.stripe, color: col('heat') },
titleStyle: { ...panel.titleStyle, color: col('heat') } };
用料
- 功能
- 框内或正文中的分栏横跨页面的框设计过的章首页标题属性锚定设计元素页面设计中的图片色块行内标签语义调色板标注框图就放在这里段落样式成品尺寸在Canvas上绘制页面编号题注来源与出处行浮动框基线网格通栏章首色带
- 类型
- Rethink Sans, Bitter, Saira Condensed(SIL OFL 1.1)
- 素材
- The plan of the street, the heat map, the bar chart and the School of Geography's mark, drawn in code from synthetic data in the poster's palette (Ignacio Ferro, CC BY 4.0)
做法
#1 · 以72 dpi排整张海报
const SHEET = { width: 600, height: 800, margin: 25 }; // mm: a portrait board, 25 mm all round
const GAP = 12; // mm between the two body columns and between the three panel columns
// The summary's leading is the page's baseline grid: 56 lines fill the 750 mm between the
// margins, so a box floated to the foot of the page ends on the bottom margin.
const LEAD = (((SHEET.height - 2 * SHEET.margin) / 25.4) * 72) / 56; // 37.96 pt
const page = { width: mm(SHEET.width), height: mm(SHEET.height),
// At 72 dpi a point is a pixel: the page is 1,701 × 2,268 px. The default 300 dpi would give
// 7,087 × 9,449 px (268 MB of canvas) for the same line breaks.
dpi: 72, backgroundColor: col('paper'),
margins: { top: mm(SHEET.margin), bottom: mm(SHEET.margin), left: mm(SHEET.margin),
right: mm(SHEET.margin) } }; // one sheet, nothing to mirror
在默认的300 dpi下,海报的断行和72 dpi时完全一样,但页面尺寸是7,087 × 9,449 px,绘制出来是268 MB的像素(页面尺寸预设)。在72 dpi下一个点就是一个像素。查看器用renderPageToCanvas加scale绘制缩略图,renderPage输出会议线上展厅要求的1,701 × 2,268 px PNG(把页面渲染成位图)。行距把上下页边距之间的750 mm分成56行,所以浮动到页脚的关键词长条正好结束在下页边距上。行距取整为38 pt时只能排55行,最后一行离页边距还差12.7 mm;关键词长条就放不进面板下方,移到了第二页。
#2 · 用标题画出标题色带
const BAND = 158; // mm from the top edge to the foot of the green field
const type = (id, content, family, size, look, placement) => ({ kind: 'text', id, content,
fontFamily: family, fontSize: pt(size), color: col('paper'), align: 'left',
overflow: 'wrap', lineHeight: 1.2,
...look, placement });
const band = { enabled: true,
// The field ends 133 mm under the top margin; eleven grid lines (147 mm) start the summary
// 14 mm below it.
minHeight: pt(11 * LEAD),
slot: { elements: [
{ kind: 'box', id: 'field', style: { backgroundColor: col('canopy') },
placement: { ...at('page', 'top-left'), size: { width: 'fill', height: mm(BAND) } } },
type('meeting', '{attr.meeting}', 'Saira Condensed', 22, { fontWeight: 600,
textTransform: 'uppercase', letterSpacing: pt(3.5), color: col('tint') },
{ ...at('page', 'top-left', SHEET.margin, 18), size: { width: mm(420) } }),
type('title', '{titleText}', 'Bitter', 110, { fontWeight: 800, lineHeight: 1 },
{ ...at('#meeting', 'below', 0, 7), size: { width: mm(380) } }),
type('authors', '{attr.authors}', 'Rethink Sans', 30, { fontWeight: 700 },
{ ...at('#title', 'below', 0, 7), size: { width: 'fill' } }),
// The affiliation marks are the characters ¹ ² ³, typed in the heading's attributes.
type('affiliations', '{attr.affiliations}', 'Rethink Sans', 21, { color: col('tint') },
{ ...at('#authors', 'below', 0, 2), size: { width: 'fill' } }),
type('number', '{attr.poster}', 'Saira Condensed', 30, { fontWeight: 700,
color: col('canopy'), box: { backgroundColor: col('paper'),
padding: { top: mm(1.5), right: mm(4), bottom: mm(1), left: mm(4) } } },
at('page', 'top-right', -SHEET.margin, 15)),
// The School of Geography's mark, drawn in code.
{ kind: 'image', id: 'mark', resourceId: 'mark',
placement: { ...at('page', 'top-right', -SHEET.margin, 38), size: { width: mm(92) } } },
] } };
H1把会议名称、海报编号、作者和单位写成属性,它的版面设计把这些内容排在一个锚定在页面上、158 mm深的绿色框上(通栏与高级版面设计)。这个框在上页边距下方133 mm处结束。不设minHeight时,摘要会从绿色下方0.9 mm处开始;minHeight设为十一个网格行,留出14 mm。单位标记用的是字符¹ ² ³,它们是Latin-1范围内仅有的上标数字。
#3 · 把面板排进一个通栏的分栏组
// The body text runs in two columns and the panels in three: a :::columns group in the
// text, and span="page" lays it across both body columns, the gutter apart.
// :::columns{count=3 breaks="3,4" span="page" marginBottom="0.75em"}
// ← panel 3 opens column 2, panel 4 column 3
// :::callout{type="panel" title="Introduction"} ← each panel is a box in the group
// …
// ::: ← closes the panel; then the other panels
// ::: ← closes the columns group
// marginBottom sets the space under the group: without it the group is followed by a
// line of the summary's paragraph spacing, 38 pt.
// A box in a group takes the width of its column. Its one device is a 6 pt stripe along
// the top.
const panel = { id: 'panel', backgroundEnabled: false,
stripe: { enabled: true, side: 'top', width: pt(6), color: col('canopy') },
padding: { top: mm(5), right: pt(0), bottom: pt(0), left: pt(0) },
titleStyle: { fontFamily: 'Saira Condensed', fontSize: pt(40), fontWeight: 700,
textTransform: 'uppercase', letterSpacing: pt(4), color: col('canopy'), gap: mm(4) },
body: { fontSize: pt(22), lineHeight: pt(30) }, // the rest follows bodyText
marginTop: mm(18) };
const results = { ...panel, id: 'results', // the finding: the same panel, striped in heat
stripe: { ...panel.stripe, color: col('heat') },
titleStyle: { ...panel.titleStyle, color: col('heat') } };
正文排两栏,面板排三栏,所以网格是直接写在正文里的一个:::columns{count=3}分栏组,span="page"让它在摘要下方横跨两个正文栏,各栏之间隔着页面的栏间距(:::columns)。不另作设定时,正文里的分栏组下方会跟一行段间距,这里是38 pt,关键词长条就会移到第二页;在围栏上写marginBottom="0.75em",用它取代这一行(postext 1.28),长条就能留在页脚。每块面板是分栏组里的一个标注框:它有自己的样式,宽度取栏宽175 mm,与上方面板之间有18 mm的marginTop(:::callout容器)。breaks="3,4"把第三块面板Results送到中间一栏顶部,把第四块Conclusions送到最后一栏顶部。不设它时,分栏组会自行齐底,在最接近总高三分之一处的面板切开。按现在的文字,切点正好落在这两块面板上;文字改动后,这个属性让切点保持不变。
#4 · 让每幅图留在自己的面板里
// "Figure 1", not "Figure 1.1": the poster has no chapters.
const figureType = { ...defaultResourceTypes(LANG)[0], numberingTemplate: '{n}' };
const resourceTypes = [figureType];
const figure = (id, [width, height], caption, altText) => ({ id, typeId: figureType.id,
kind: 'svg', svg: { fileId: `${id}.svg`, width: width * 10, height: height * 10 },
placement: { position: 'here' }, // stays in its panel, where ::resource puts it; else floats
caption, altText, note: t({ en: 'Synthetic data, generated for this poster.',
es: 'Datos sintéticos, generados para este póster.' }), createdAt: 0, updatedAt: 0 });
placement为'here'的图留在::resource所在的面板里;用默认placement时,三幅图会离开各自的面板,海报排到第二页。numberingTemplate: '{n}'把它们编为1、2、3,而默认的{h1}.{n}会在H1标题下印出Figure 1.1(资源类型)。每条题注下的说明写明数据是合成的。
#5 · 热力图和图例共用颜色
const palette = {
ink: '#102a2c', // text: a green-black
paper: '#f7faf7', // the sheet, and type on the band
canopy: '#2e7d4f', // the band, the stripes and titles of five panels, the tree crowns
tint: '#e6f2ea', // the keyword strip, the park on the plan, lines of type on the band
rule: '#bcd2c4', // buildings on the plan, the chart's grid
muted: '#587068', // the notes under the figures, the axis titles inside them
// The key of Figure 2, the air against the street mean at the same hour. The heat map's
// cells and the :swatch runs of its key read the same four entries.
cool: '#3b82c4', // −1.5 °C or less
mist: '#a9c9e6', // −1.5 to 0 °C
blush: '#f2b492', // 0 to +1.5 °C
heat: '#d9572b', // +1.5 °C or more; also −4.2 °C, the Results panel, the loggers, the sun
};
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [ // defaults link to 'main-color': point it at the canopy green
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
{ id: 'main-color', name: 'canopy (defaults)', value: { hex: palette.canopy, model: 'hex' } },
];
热力图的格子和图例的四个:swatch{color="…"}片段引用相同的调色板条目,所以给cool换一个值,热力图和图例会一起重新着色(行内格式)。图例是Results面板里的第二个:::columns分栏组,每栏两个条目。
#6 · 用段落样式排核心数字
const paragraphStyles = [
// Paragraph styles apply inside boxes. The figure is written **bold**: that sets it in
// Bitter 700 and in the style's boldColor.
// containerSpacing 'add': the group ends on the style's own space, with no line of
// paragraph spacing under it. −4.2 °C sits on the line that explains it, and a :::space
// sets the gap under the references.
{ id: 'stat', fontFamily: 'Bitter', fontSize: pt(150), lineHeight: pt(130),
boldColor: col('heat'), containerSpacing: 'add' },
{ id: 'refs', fontSize: pt(19), lineHeight: pt(26), hangingIndent: mm(9), spaceBetween: pt(8),
containerSpacing: 'add' },
{ id: 'key', fontSize: pt(19), lineHeight: pt(28) }, // the key of Figure 2
];
const chipStyles = [{ id: 'keyword', background: col('paper'), borderColor: col('canopy'),
borderWidth: pt(1.5), borderRadius: em(1), paddingX: em(0.55), paddingY: em(0.14),
color: col('canopy'), bold: true, gap: em(0.35) }];
const strip = { id: 'strip', background: col('tint'), // one device: a tint
padding: { top: mm(4), right: mm(8), bottom: mm(4), left: mm(8) }, columnGap: mm(GAP),
body: { fontSize: pt(18), lineHeight: pt(24) } };
段落样式在框内同样生效,所以−4.2 °C是Results面板里的一个:::paragraphs{style="stat"}块,用150 pt的Bitter(段落样式)。数字写成粗体,所以以Bitter 700印出,并取样式的boldColor,也就是面板的橙色。另一个样式给参考文献设9 mm的悬挂缩进。关键词长条是一个带底色的框,placement="bottom",浮动到网格下方的页脚。
完整食谱
// ═══ Postext Cookbook · Nº 059 · Research poster on one big page ══════════════════
// https://postext.dev/en/cookbook/research-poster
// Code: MIT · Text and data: original, synthetic (CC BY 4.0) · Figures: generated in code
// Fonts: Rethink Sans, Bitter, Saira Condensed (SIL OFL 1.1) · Needs postext ≥ 1.28.0
import {
buildDocumentWithFonts, renderPage, renderPageToCanvas, registerResourceImage,
defaultResourceTypes, inlineSvgFonts,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'research-poster';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: six colours for the poster, four for the heat map's key
const palette = {
ink: '#102a2c', // text: a green-black
paper: '#f7faf7', // the sheet, and type on the band
canopy: '#2e7d4f', // the band, the stripes and titles of five panels, the tree crowns
tint: '#e6f2ea', // the keyword strip, the park on the plan, lines of type on the band
rule: '#bcd2c4', // buildings on the plan, the chart's grid
muted: '#587068', // the notes under the figures, the axis titles inside them
// The key of Figure 2, the air against the street mean at the same hour. The heat map's
// cells and the :swatch runs of its key read the same four entries.
cool: '#3b82c4', // −1.5 °C or less
mist: '#a9c9e6', // −1.5 to 0 °C
blush: '#f2b492', // 0 to +1.5 °C
heat: '#d9572b', // +1.5 °C or more; also −4.2 °C, the Results panel, the loggers, the sun
};
// Every colour is linked to its palette entry by id.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [ // defaults link to 'main-color': point it at the canopy green
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
{ id: 'main-color', name: 'canopy (defaults)', value: { hex: palette.canopy, model: 'hex' } },
];
// #endregion
// #region sheet: one 600 × 800 mm page, laid out at 72 dpi
const SHEET = { width: 600, height: 800, margin: 25 }; // mm: a portrait board, 25 mm all round
const GAP = 12; // mm between the two body columns and between the three panel columns
// The summary's leading is the page's baseline grid: 56 lines fill the 750 mm between the
// margins, so a box floated to the foot of the page ends on the bottom margin.
const LEAD = (((SHEET.height - 2 * SHEET.margin) / 25.4) * 72) / 56; // 37.96 pt
const page = { width: mm(SHEET.width), height: mm(SHEET.height),
// At 72 dpi a point is a pixel: the page is 1,701 × 2,268 px. The default 300 dpi would give
// 7,087 × 9,449 px (268 MB of canvas) for the same line breaks.
dpi: 72, backgroundColor: col('paper'),
margins: { top: mm(SHEET.margin), bottom: mm(SHEET.margin), left: mm(SHEET.margin),
right: mm(SHEET.margin) } }; // one sheet, nothing to mirror
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#以150 dpi导出电子海报
会议要求更大的文件时,得到一张3,543 × 4,724 px的PNG,断行不变。
- dpi: 72, backgroundColor: col('paper'),
+ dpi: 150, backgroundColor: col('paper'),常见问题
- Rethink Sans在Canvas上会把括号里的单个数字画成带圈数字,例如11(3)里的期号,所以参考文献只给出卷号和页码。
- 位于文档末尾的通栏框下方若留不出两行正文的空间,就会移到新的一页。所以关键词长条用
placement="bottom"浮动,排在下页边距上,位于网格下方剩下的50 mm里。 - 在
stat和refs两个样式上写containerSpacing: 'add',它们的:::paragraphs组就以样式自身的间距收尾,这样−4.2 °C就紧贴着解释它的那一行;海报里其余的组仍按文档的规则(postext 1.28起;此前这条规则只能用bodyText.paragraphContainerSpacing对整份文档设定)。在最后一条参考文献下方,这个间距是样式的spaceBetween,即2.8 mm,所以在致谢之前加一个:::space{lines=0.75},空出10.8 mm,接近面板里其他段落之间的10.6 mm。不写它,按文档的'collapse',组后面会跟一行面板的段间距:致谢不再需要:::space,但−4.2 °C下方多出的一行会把关键词长条挤到第二页。
致谢
- 文本
- 原创文字, CC BY 4.0
- 图片
- The plan of the street, the heat map, the bar chart and the School of Geography's mark, drawn in code from synthetic data in the poster's palette · Ignacio Ferro · CC BY 4.0
- 字体
- Rethink Sans (SIL OFL 1.1) · Bitter (SIL OFL 1.1) · Saira Condensed (SIL OFL 1.1)


