跳到主要内容
食谱编号57

排版食谱 · 第1章 · 页面与网格

带侧栏的单页简历

一页A4简历:紫红色侧栏是左侧纯浮动栏里的一个框,页眉框把它延伸到页边,工作经历的起止年份右对齐。

本页内容
输出
Canvas
难度
中级
Postext
已用Postext 1.65.0测试
需要≥ 1.25.0
许可证
更新于2026年10月11日
代码MIT · 文本CC BY 4.0
  • 英文样例:尚无中文版本
  • 成品尺寸210 × 297 mm
  • 一栏半, 栏间距10 mm
  • Hanken Grotesk 9.3/13.2
  • Hedvig Letters Serif
  • 1页
  • 难度
  • Postext 1.57.1
  • 排版用时46 ms
  • 176行代码

简单来说

一位图书设计师的单页简历,左侧有一条彩色侧栏,放联系方式和技能。每段工作经历的日期都靠右对齐。

成品一览

Irene Salcedo是马德里一位虚构的图书设计师,这是她的简历,排在一张A4纸上。一条66 mm宽的紫红色色带沿左边缘从纸张顶端一直延伸到底端。色带顶部是一摞用代码画出的布面精装书,与她姓名的基线平齐。书下方依次是联系方式、排成标签的技能与工具、语言、教育背景、教学经历和工作之外的爱好。她的姓名用46 pt的Hedvig Letters Serif排出,位于118 mm宽的正文栏顶部,下面是五行简介、三份工作和她设计过的图书列表。每份工作的标题行左边是职位,右边是起止年份,两者在同一条基线上,雇主以斜体列在下一行。侧栏的第一个标题与姓名下方的职业头衔共用一条基线。

这道食谱解答

  • 怎样做一栏半版式,一个宽的正文栏加一个窄的侧栏?
  • 怎样给每一页加水印、背景底色或装饰图片?
  • 怎样做行内标签:键盘按键、标签、练习用的词库?

简短回答

script.js · 第47–67行在完整代码中
const layout = {
  layoutType: 'oneAndHalf',
  sideColumnPercent: (SIDE / CONTENT) * 100, // 57 of the 185 mm between the margins
  sideColumnSide: 'left',
  sideColumnRole: 'floats', // no body text: only boxes fenced with span="side"
  gutterWidth: mm(GUTTER), // the text column keeps 185 − 57 − 10 = 118 mm
};
// A side box stands where the text has reached at its fence, so the Markdown opens with it,
// before the name, and it starts at the head of the column (gotcha: side-box-starts-at-fence):
//   :::callout{type="sidebar" span="side"}
//   :::callout{type="section" title="Contact"} … :::     ← the sections nest inside it
//   …
//   :::space{lines=2.76}    ← last: runs the band to the column's foot; a fifth of a line
//   :::                       more and the whole box moves to page 2
//   # Irene Salcedo {role="Book designer and art director"}
const sidebar = { id: 'sidebar', background: col('band'),
  // The first title stands on the role's line. The text starts 10 mm from the trim, the
  // left margin plus 1 mm, and stops 10 mm short of the band's right edge.
  padding: { top: mm(ROLE_Y), right: mm(10), bottom: pt(0), left: mm(1) },
  body: { fontFamily: SANS, fontSize: pt(8.4), lineHeight: pt(12.4), color: col('paper'),
    boldColor: col('paper'), paragraphSpacing: false } };

用料

类型
Hedvig Letters Serif, Hanken Grotesk(SIL OFL 1.1)
素材
  • The stack of books at the head of the sidebar, drawn in code in the page's palette (Ignacio Ferro, CC BY 4.0)

做法

#1 · 把各部分嵌套在一个侧栏框里

script.js · 第91–102行在完整代码中
// The sections nest in one side box. As separate side boxes they would stand at least a line
// of paper apart (gotcha: side-boxes-line-apart). A nested box ignores span and flows inside
// its parent (gotcha: nested-callout-limits).
const section = (id, lineHeight) => ({ id, backgroundEnabled: false, // the band shows through
  padding: { top: pt(0), right: pt(0), bottom: pt(0), left: pt(0) },
  marginTop: mm(10),
  titleStyle: { ...caps('glow'), gap: mm(2.4) },
  body: { ...sidebar.body, lineHeight: pt(lineHeight) } });
const chipStyles = [{ id: 'skill', fontFamily: SANS, fontSize: pt(7.6), bold: true,
  background: col('chip'), color: col('paper'), borderWidth: pt(0),
  borderRadius: em(1), // past half the chip's height: a pill
  paddingX: em(0.6), paddingY: em(0.22), gap: em(0.3) }];

在侧栏里,色带就是简短回答中的那个框。它的围栏写在姓名之前,所以span="side"把它放在纯浮动栏的顶部。各部分是嵌套在它里面的框,自身没有填充色,于是紫红色从Contact一直连到Outside work,中间不断开。如果把它们做成各自独立的侧栏框,即使marginBottom设为0,彼此之间也会隔开4.7到9.1 mm。标签高约3.9 mm。Skills和Tools用单独的部分样式chips,其16 pt行距让两行标签之间留出1.8 mm;其他部分用的12.4 pt只会留出半毫米(行内标签样式)。

#2 · 给栏外的页边上色

script.js · 第71–87行在完整代码中
// Header elements are painted after the text, over it, so these stay in the margins, where
// no text runs (gotcha: header-paints-over-text). They repeat on every page.
const BAND_W = LEFT + SIDE; // mm from the trim edge to the band's right edge
const SEAM = 0.5; // mm of overlap with the box, so no hairline of paper shows between them
const REACH = 1; // mm the foot box climbs above the column's foot, over the end of the box
const bandBox = (id, x, y, w, h) => ({ kind: 'box', id, style: { backgroundColor: col('band') },
  placement: { ...at('page', 'top-left', x, y), size: { width: mm(w), height: mm(h) } } });
const header = { elements: [
  bandBox('head', 0, 0, BAND_W, TOP + SEAM), // above the column: the top margin
  bandBox('edge', 0, 0, LEFT + SEAM, TRIM_H), // beside it: the left margin, top to bottom
  bandBox('foot', 0, TRIM_H - BOTTOM - REACH, BAND_W, BOTTOM + REACH), // below it
  // Painted last, over the box's top padding, where no text runs. The bottom of the stack
  // sits on the name's baseline.
  { kind: 'image', id: 'books', resourceId: 'books', placement: {
    ...at('page', 'top-left', LEFT + 1, TOP + BASELINE - BOOKS.h),
    size: { width: mm(BOOKS.w), height: mm(BOOKS.h) } } },
] };

侧栏位于页边距以内,所以侧栏框离左边缘还差9 mm,离顶端还差18 mm。三个页眉框分别填满栏上方的上页边距、从顶到底的左页边距,以及栏下方的下页边距。页眉元素在文字之后绘制、盖在文字之上,所以本食谱把它们限制在没有文字的页边里。它们还会在每一页重复,如果有第二页,也会带上这条色带(页眉与页脚)。顶部和左侧的框与侧栏框重叠0.5 mm,底部的框比栏底高出1 mm,盖住侧栏框的末端,这样接缝处不会露出一丝纸色。结束侧栏框的:::space把框延伸到278.0 mm,比栏底高0.8 mm;英文版用2.76行,西班牙文版用1.76行。

#3 · 把姓名放在正文栏顶部

script.js · 第106–118行在完整代码中
const nameplate = { enabled: true, slot: { elements: [
  { kind: 'text', id: 'name', content: '{titleText}', fontFamily: SERIF,
    fontSize: pt(NAME.size), lineHeight: 1, color: col('ink'),
    placement: at('container', 'top-left') },
  { kind: 'text', id: 'role', content: '{attr.role}', ...caps('accent'),
    placement: at('#name', 'below', 0, NAME.gap) },
] } };
const nameLevel = { level: 1, // span stays 'column': the name heads the text column only
  // No break before the name: the sidebar box is already on the page, and a break would
  // move the name and the whole text column to page 2.
  breakBefore: { enabled: false },
  marginBottom: pt(LEAD), // one grid line of air under the role
  advancedDesign: nameplate };

H1保留默认的span: 'column'。设为'page'时,它会变成横跨两栏的章首标题;由于它排在侧栏框之后,就会移到第2页,而那里的侧栏要到姓名下方45.9 mm处才开始。breakBefore关闭,因为侧栏框已经在这一页上:如果分页,姓名和整个正文栏都会移到第2页。这一级标题的marginBottom为一个网格行,使简介从45.9 mm而不是41.3 mm处开始。侧栏框的上内边距是ROLE_Y,即姓名的高度加上其下方的间距,所以侧栏的第一个标题与职业头衔共用一条基线,距离顶边39.3 mm。

#4 · 把日期放在职位那一行

script.js · 第130–149行在完整代码中
const JOB = 9.8; // pt: the job title, the dates and the employer share the size and leading
const jobText = (id, content, look) => ({ kind: 'text', id, content, fontFamily: SANS,
  fontSize: pt(JOB), lineHeight: LEAD / JOB, // the body's leading, as a multiple of the size
  align: 'left', ...look }); // without align, design text is centred in its box
const job = { enabled: true, slot: { elements: [
  jobText('title', '{titleText}', { fontWeight: 700, color: col('ink'), overflow: 'wrap',
    placement: { ...at('container', 'top-left'), size: { width: mm(84) } } }), // clear of dates
  jobText('dates', '{attr.dates}', { color: col('muted'),
    placement: at('container', 'top-right') }), // the title's top and size, so its baseline
  jobText('org', '{attr.org}', { italic: true, color: col('muted'),
    placement: at('#title', 'below') }),
] } };
const jobLevel = { level: 3, fontSize: pt(JOB), lineHeight: pt(LEAD), marginTop: pt(9),
  marginBottom: pt(0), advancedDesign: job };
// The section head takes 20 pt under 19.6 pt of space, three grid lines, so a job head
// starts the same 9 pt under a grid line after a section head as after a list. The 9 pt
// below it merge with a job head's 9 pt above. Under Selected books they push the list to
// the next grid line, as the default 7 pt would; with 0 it would start one line higher.
const sectionLevel = { level: 2, fontSize: pt(14), lineHeight: pt(20),
  marginTop: pt(3 * LEAD - 20), marginBottom: pt(9), advancedDesign: sectionHead };

每份工作是一个H3,其属性带着雇主和起止年份:### Art director {org="Ediciones del Albardín, Madrid" dates="2021 – present"}(标题属性)。职位和日期都锚定在同一个容器的顶部,各占一角,字号和行距相同,因此落在同一条基线上。职位限宽84 mm并允许换行:过长的职位会在碰到日期之前折到第二行,雇主随之下移。加上上方的空白,每个部分标题正好占三个网格行,所以无论工作标题跟在部分标题还是列表之后,都位于某条网格线下方9 pt处。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 057 · One-page CV with a sidebar ═══════════════════════
// https://postext.dev/en/cookbook/cv-with-sidebar
// Code: MIT · Text: original (CC BY 4.0) · Drawing: made in code (CC BY 4.0)
// Fonts: Hedvig Letters Serif, Hanken Grotesk (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 = 'cv-with-sidebar';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = {
  ink: '#231b22', // text: a plum-tinted near-black
  band: '#3a2235', // the sidebar
  accent: '#8f3b62', // on paper: the role and the section heads (7.1:1)
  glow: '#f1b98f', // on the band: the sidebar titles (8.3:1)
  chip: '#744d6c', // on the band: the skill chips
  rule: '#d9cdd5', // the hairlines after the section heads
  muted: '#6c5f69', // dates, employers, the colophon (6.0:1)
  paper: '#ffffff', // the page, and the text on the band (14.4:1)
};
// Each colour carries its hex and the palette entry it follows.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries({ ...palette, 'main-color': palette.accent })
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
const [SERIF, SANS] = ['Hedvig Letters Serif', 'Hanken Grotesk'];
const PT = 25.4 / 72; // mm in a point
const [TRIM_W, TRIM_H] = [210, 297]; // mm: A4, printed on one side, so nothing is mirrored
const [TOP, LEFT, RIGHT] = [18, 9, 16]; // mm
const LEAD = 13.2; // pt: the body leading
const BOTTOM = TRIM_H - TOP - 56 * LEAD * PT; // mm: the text block holds 56 lines
const CONTENT = TRIM_W - LEFT - RIGHT; // 185 mm between the margins
const [SIDE, GUTTER] = [57, 10]; // mm: the sidebar column, and the white after it
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const LABEL = 7.8; // pt: the role and the sidebar titles, tracked capitals
const caps = (colour) => ({ fontFamily: SANS, fontSize: pt(LABEL), fontWeight: 700,
  textTransform: 'uppercase', letterSpacing: pt(LABEL * 0.18), color: col(colour) });
const NAME = { size: 46, gap: 2.6 }; // pt and mm: the name, and the room under it
const ROLE_Y = NAME.size * PT + NAME.gap; // mm under the top margin: the role's line
// mm under the top margin: the name's baseline. Hedvig Letters Serif, set solid, puts it 0.795
// of the size down the line (measured on the page); another face needs its own ratio.
const BASELINE = 0.795 * NAME.size * PT;
const BOOKS = { w: 46, h: 18 }; // mm: the drawing at the head of the band

// #region answer: a float-only column on the left, filled by one box
const layout = {
  layoutType: 'oneAndHalf',

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

变化

#给色带换色

每种颜色只在palette里写一次,色带框、侧栏框、标签、职业头衔、各级标题和插图都从那里取色。下面三行把色带、强调色和标签改成青绿色。

-  band: '#3a2235', // 侧栏
+  band: '#1d3b3a', // 侧栏
-  accent: '#8f3b62', // 用在纸面上:职业头衔和各部分标题(7.1:1)
+  accent: '#2b5f5b', // 用在纸面上:职业头衔和各部分标题(7.3:1)
-  chip: '#744d6c', // 用在色带上:技能标签
+  chip: '#456d69', // 用在色带上:技能标签

#把图浮动到同一栏

带边注栏的教科书把图、侧边题注和旁注放在每页外侧的一个纯浮动栏里。

常见问题

易错点

侧栏框与其围栏之后的块齐平开始

在postext 1.4.1中,span: 'side'的框在侧栏中的位置,是正文排到其围栏处时的高度,落在下一个网格行上,并排在已在那里的框之下。把旁注围在它所解释的段落之前:围在段落之后,旁注就会从下一段旁边开始。会超出栏底的框会向上滑,在上方框允许的范围内,直到底边落在栏底;仍然放不下的,就等到下一页的侧栏。 旁注 →

易错点

侧栏中叠放的框之间总隔着一行空白

在postext 1.4.1中,span: 'side'的框下面至少留出一个正文行的空间,才接侧栏里的下一个内容,并向上取整到基线网格,不管它的marginBottom怎么写。因此共用背景的框永远不会相接:叠放在一起时,看起来是一张张独立的卡片。要得到一整块连续的面板,只围一个侧栏框,把各部分嵌套在里面。 旁注 →

易错点

:::space在框顶或栏顶会被丢掉

在栏顶、:::columns组顶部、还有其他内容的无标题框的顶部,以及被拆分的框的接续部分顶部,:::space会被丢掉。从postext 1.5起,只由:::space组成的框高度等于所要求的空白(答题框、填写用的空间),紧接在框标题下面的空白会让框内正文相应地往下开始。要让无标题框以空白开头,给它一个标题或一行首行,再在后面加空白。 显式竖向间距 →

易错点

页眉和页脚元素画在正文之上

页眉和页脚元素画在页面上层,正文区域不会为它们让出位置。把它们放在页边距以内,为它们预留空间的正是页边距。 书眉与页码 →

易错点

嵌套框忽略span、placement和snapToGrid

嵌套在另一个标注框中的标注框会忽略自己的span、placement、snapToGrid和floatBarrier:它总是在父框内部排,宽度为父框的内宽。 嵌套框 →

  • 让:::space与页面吻合。英文版中,2.76行使框结束在栏底上方0.8 mm处。设为2.96行时,框超出栏底0.1 mm,整个侧栏会移到第2页;设为2.66行时,框与底部的框之间会露出一条纸色。
  • 姓名的版面设计里的框画不了这条色带。标题会按框的高度预留空间,所以与色带一样高的框会让它预留超过栏高260.8 mm的高度,正文就会移到第2页。加上reserve: false后框不再预留空间,但留在栏内的设计会在栏底被截断,下页边距仍是白的。

致谢

文本
原创文字, CC BY 4.0
图片
  • The stack of books at the head of the sidebar, drawn in code in the page's palette · Ignacio Ferro · CC BY 4.0
字体
Hedvig Letters Serif (SIL OFL 1.1) · Hanken Grotesk (SIL OFL 1.1)
沙盒