跳到主要内容
食谱编号95

排版食谱 · 第5章 · 图书结构

温哥华格式的医学论文

一篇A4双栏的临床试验报告:上标引用序号,温哥华格式的编号参考文献表,DOI在PDF中是可点击的链接。

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

页码181 · 第1页,共3页

  • 英文样例:尚无中文版本
  • 成品尺寸210 × 297 mm
  • 2栏, 栏间距6 mm
  • PT Serif 9.3/12.8
  • Fira Sans
  • Fira Sans Condensed
  • Fira Sans@tnum
  • 3页
  • 难度
  • Postext 1.65.0
  • 排版用时298 ms
  • 180行代码

简单来说

一篇医学研究短文,按期刊页面排版。作者用代号引用文献;Postext在正文里印出小号上标数字,并在文末生成编号的参考文献表,每个DOI都是链接。

成品一览

一本临床期刊的三页:报告一项试点试验的原创论文,按遵循ICMJE规范的期刊那样排在A4纸上,分两栏。第一页顶部横贯一条深青色刊头,下面依次是文章类型、三行标题、带上标单位序号的作者,以及浅色底纹上的结构式摘要。作者用BibTeX代号引用,页面呈现医学编辑期望的样子:句号后的小号上标数字,连续文献合并为6–8,不连续的两篇紧排为6,9,以及NLM格式的编号参考文献表,如Lancet 2016;387(10022):957–67,每条末尾是该文献的DOI。在PDF中,每个序号都跳到对应的参考文献,每个DOI都能打开原文。试验是虚构的;所引的十一篇文献都真实存在。

这道食谱解答

  • 怎样像医学期刊那样把引用序号排成上标,并让DOI成为可点击的链接?
  • 怎样按APA、IEEE或其他引用样式引用文献并生成参考文献表?

简短回答

script.js · 第29–49行在完整代码中
// [@key] prints a raised number in order of first citation. English journals set it after
// the full stop, "control.[@ncdrisc2021]"; Spanish ones before it, "controlada[@ncdrisc2021].".
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
// elsevier-vancouver is the bundled NLM/Vancouver style (citation-sequence). Two edits bring
// its list to the NLM sample references: "1." instead of "[1]", and the issue after the
// volume, 2015;373(22):2103-16.
const vancouver = STYLES['elsevier-vancouver']
  .replace('<text variable="citation-number" prefix="[" suffix="]"/>',
    '<text variable="citation-number" suffix="."/>')
  .replace('<text variable="volume"/>',
    '<group><text variable="volume"/><text variable="issue" prefix="(" suffix=")"/></group>');
const citations = {
  style: 'custom', customStyle: vancouver,
  marker: 'superscript', collapseRanges: true, // raised 1 and 6–8, not [1] and [6–8]
  link: true, // each number jumps to its reference, in the PDF and on screen
  // 7.8 pt: the eleven societies of reference 5, ACC/AHA/…/PCNA, fit one line whole
  bibliography: { fontSize: em(0.84), lineHeight: pt(10.4), entrySpacing: pt(1.6),
    labelWidth: mm(5.5), labelAlign: 'right', // a column for the numbers: 9. and 10. end
    // together, and every entry's text starts at one x, first line and turnovers alike
    doi: 'link' }, // https://doi.org/… printed whole and clickable
};

用料

类型
PT Serif, Fira Sans, Fira Sans Condensed(SIL OFL 1.1)
素材
无:所有图片都用代码绘制

做法

#1 · 温哥华格式,上标并带链接

代码就是上面的简短回答。引擎自带的样式中,elsevier-vancouver遵循NLM的Citing Medicine(按引用顺序编号,作者写作Ettehad D, Emdin CA,列六位后加et al.,期刊名用缩写),所以从这个文件出发。两处字符串替换让它的文献表符合NLM的示例:序号写作1.而不是[1],期号跟在卷号后面。marker: 'superscript'不论样式怎么写,都把引用排成上标数字;doi: 'link'让每个https://doi.org/地址保持为链接。英文的上标放在句号之后;西班牙文按学院正字法放在句号之前,只要把[@key]写在句号前即可。两篇序号不连续的文献紧排为6,9:逗号后若有空格,会随两端对齐的行拉宽。文献表中,labelWidth给序号单独留出一栏,labelAlign: 'right'让*9.和10.*右端对齐,于是每条正文的首行和转行都从同一位置开始。AMA样式也随引擎提供,它自己就把序号排成上标,但文献表的标点和页码区间与温哥华格式不同。

#2 · 横跨两栏的标题区

script.js · 第53–83行在完整代码中
const text = (id, content, family, size, extra) => ({ kind: 'text', id, content, align: 'left',
  fontFamily: family, fontSize: pt(size), color: col('ink'), overflow: 'wrap', ...extra });
const at = (to, edge, x, y, width) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) },
  ...(width && { size: { width: mm(width), height: 'auto' } }) });
const caps = { fontFamily: COND, fontWeight: 600, letterSpacing: pt(1.3),
  textTransform: 'uppercase' };
const JOURNAL = t({ en: 'Almenara Medical Journal', es: 'Revista Médica de Almenara' });
const titleBlock = { enabled: true,
  minHeight: mm(62), // the abstract and the text start under the note, on both columns
  slot: { elements: [
    { kind: 'box', id: 'band', style: { backgroundColor: col('accent') },
      placement: { anchor: { to: 'page', edge: 'top-left' },
        size: { width: 'fill', height: mm(15) } } },
    text('journal', JOURNAL, COND, 9.5, { ...caps, color: col('paper'),
      placement: at('page', 'top-left', INNER, 6) }),
    text('issue', '{attr.issue}', COND, 9.5, { ...caps, color: col('paper'),
      align: 'right', placement: at('page', 'top-right', -OUTER, 6, 60) }),
    text('kind', '{attr.kind}', COND, 9, { ...caps, color: col('accent'),
      placement: at('container', 'top-left', 0, 0, MEASURE) }),
    text('title', '{titleText}', SANS, 19.5, { fontWeight: 600, lineHeight: 1.16,
      placement: at('#kind', 'below', 0, 3, MEASURE - 20) }),
    text('authors', '{attr.authors}', SERIF, 10.5, { inlineMarks: true, // ^1^ → ¹
      placement: at('#title', 'below', 0, 4.5, MEASURE) }),
    text('affiliations', '{attr.affiliations}', SANS, 7.4, { inlineMarks: true,
      lineHeight: 1.35, color: col('muted'), placement: at('#authors', 'below', 0, 2, MEASURE) }),
    { kind: 'rule', id: 'rule', thickness: pt(0.5), color: col('rule'),
      placement: at('#affiliations', 'below', 0, 3, MEASURE) },
    text('note', '{attr.note}', SANS, 7.4, { color: col('muted'),
      placement: at('#rule', 'below', 0, 1.6, MEASURE) }),
  ] },
};

文章标题是唯一的一级标题,使用article样式,该样式通栏,用自己的设计绘制标题。文章类型、作者、单位和注释都来自标题属性。inlineMarks把属性里的^1^变成上标的单位序号,单位列表中的\n让每个机构另起一行。色带锚定在裁切边上,所以一直延伸到纸张上边缘。

#3 · 结构式摘要和要点框

script.js · 第87–97行在完整代码中
const box = (id, bold, more) => ({ id, border: { enabled: false }, snapToGrid: false,
  marginTop: pt(LEAD), marginBottom: pt(LEAD),
  titleStyle: { ...caps, fontSize: pt(8.5), color: col('accent') }, // run-in labels in bold
  body: { fontFamily: SANS, fontSize: pt(8.3), lineHeight: pt(11.2), textAlign: 'left',
    firstLineIndent: pt(0), paragraphSpacing: true, boldColor: col(bold) }, ...more });
const calloutStyles = [
  box('abstract', 'accent', { background: col('tint'), padding: mm(3.5), marginTop: pt(0) }),
  box('keypoints', 'ink', { backgroundEnabled: false, padding: { top: mm(2.5), right: mm(0),
    bottom: mm(1), left: mm(0) }, stripe: { enabled: true, side: 'top', width: pt(2.5),
    color: col('accent') } }),
];

两个框共用一种文字样式:8.3 pt的Fira Sans,段首是粗体的小标签,这是读者在摘要类内容中习惯的字体。摘要框带底纹,标签为深青色;要点框位于2.5 pt的色条下,标签用正文墨色。snapToGrid: false保留精确的内边距,让摘要框紧贴文字。

#4 · 栏顶的表1和图1

script.js · 第300–319行在完整代码中
const resources = () => [
  { id: 'tbl-baseline', typeId: 'table', kind: 'table', createdAt: 0, updatedAt: 0,
    placement: { position: 'top' },
    caption: t({ en: 'Characteristics of the patients at baseline.',
      es: 'Características de los pacientes al inicio.' }),
    note: t({ en: 'Values are mean (SD) or number (%). BP, blood pressure, in mm Hg.',
      es: 'Valores en media (DE) o número (%). PA, presión arterial, en mm Hg.' }),
    table: { model: { headerRowCount: 1, columnWidths: [2.2, 1.1, 1.1],
      rows: parseTSV(baseline).rows.map((row, r) => row.map(({ content }, c) => ({ content,
        ...(r === 0 && { isHeader: true }), ...(c > 0 && { align: 'center' }) }))) } } },
  { id: 'fig-home', typeId: 'figure', kind: 'svg', createdAt: 0, updatedAt: 0,
    placement: { position: 'top' }, svg: { fileId: 'home.svg', width: 850, height: 520 },
    caption: t({ en: 'Mean home systolic pressure by week in the telemonitoring group, with its '
      + '95% confidence interval. The dashed line is the home target of 135\u00a0mm\u00a0Hg.',
    es: 'Presión sistólica domiciliaria media por semana en el grupo de telemonitorización, con '
      + 'su intervalo de confianza del 95\u00a0%. La línea discontinua es el objetivo de '
      + '135\u00a0mm\u00a0Hg.' }),
    altText: t({ en: 'A line falling from 158 mm Hg in week 1 to 135 mm Hg in week 12.',
      es: 'Una línea que baja de 158 mm Hg en la semana 1 a 135 mm Hg en la semana 12.' }) },
];

表格从制表符分隔的文本读入,就像电子表格导出的那样,表头一行填深青色,标签为白色粗体。两个资源都浮动到引用它们的段落之后的栏顶。把shortLabel设为类型的全名后,:ref会像期刊那样印出*(Table 1)*;标题上的numbered: false让编号保持为1,而不是1.1。单元格中的Fira Sans设了figureStyle: 'tabular',每个数字等宽,两组的均值和计数上下对齐。

script.js · 第17–21行在完整代码中
const palette = { ink: '#1a1d21', accent: '#0d5c63', tint: '#e5eff0', rule: '#9fb4b6',
  muted: '#566065', paper: '#ffffff' };
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' } }));

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 095 · A medical article in Vancouver style ══════════════
// https://postext.dev/en/cookbook/medical-article-vancouver
// Code: MIT · Text: original (CC BY 4.0) · Chart: generated in code (CC BY 4.0)
// Fonts: PT Serif, Fira Sans, Fira Sans Condensed (SIL OFL 1.1) · Needs postext ≥ 1.65.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerCitationEngine, registerResourceImage,
  defaultResourceTypes, parseTSV, inlineSvgFonts,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
import { createCiteprocEngine, STYLES, LOCALES } from 'https://esm.sh/postext-citeproc';

const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'medical-article-vancouver';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: black text, one clinical teal for the journal's own marks
const palette = { ink: '#1a1d21', accent: '#0d5c63', tint: '#e5eff0', rule: '#9fb4b6',
  muted: '#566065', paper: '#ffffff' };
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' } }));
// #endregion
const [SERIF, SANS, COND] = ['PT Serif', 'Fira Sans', 'Fira Sans Condensed'];
const [TRIM_W, TRIM_H, TOP, BOTTOM, INNER, OUTER, GUTTER] = [210, 297, 24, 22, 17, 17, 6];
const MEASURE = TRIM_W - INNER - OUTER;
const LEAD = 12.8; // pt: 9.3 pt type, as journals set two columns of A4

// #region answer: Vancouver numbers as superscripts, a "1." list and DOIs that are links
// [@key] prints a raised number in order of first citation. English journals set it after
// the full stop, "control.[@ncdrisc2021]"; Spanish ones before it, "controlada[@ncdrisc2021].".
registerCitationEngine(createCiteprocEngine({ styles: STYLES, locales: LOCALES }));
// elsevier-vancouver is the bundled NLM/Vancouver style (citation-sequence). Two edits bring
// its list to the NLM sample references: "1." instead of "[1]", and the issue after the
// volume, 2015;373(22):2103-16.
const vancouver = STYLES['elsevier-vancouver']
  .replace('<text variable="citation-number" prefix="[" suffix="]"/>',
    '<text variable="citation-number" suffix="."/>')
  .replace('<text variable="volume"/>',
    '<group><text variable="volume"/><text variable="issue" prefix="(" suffix=")"/></group>');
const citations = {
  style: 'custom', customStyle: vancouver,
  marker: 'superscript', collapseRanges: true, // raised 1 and 6–8, not [1] and [6–8]
  link: true, // each number jumps to its reference, in the PDF and on screen
  // 7.8 pt: the eleven societies of reference 5, ACC/AHA/…/PCNA, fit one line whole
  bibliography: { fontSize: em(0.84), lineHeight: pt(10.4), entrySpacing: pt(1.6),
    labelWidth: mm(5.5), labelAlign: 'right', // a column for the numbers: 9. and 10. end
    // together, and every entry's text starts at one x, first line and turnovers alike
    doi: 'link' }, // https://doi.org/… printed whole and clickable

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

变化

#改用AMA样式

AMA样式自己把序号排成上标,文献表中写作doi:10.1056/…;去掉替换和标记设置即可。

-  style: 'custom', customStyle: vancouver,
-  marker: 'superscript', collapseRanges: true, // raised 1 and 6–8, not [1] and [6–8]
+  style: 'american-medical-association',

#DOI不带链接

只用于印刷的PDF,可以把地址保留为黑色纯文本。

-    doi: 'link' }, // https://doi.org/… printed whole and clickable
+    doi: 'text' },

#方括号中的序号

有些温哥华格式的期刊把序号写在行内的方括号里。

-  marker: 'superscript', collapseRanges: true, // raised 1 and 6–8, not [1] and [6–8]
+  marker: 'brackets', collapseRanges: true,

常见问题

易错点

标题样式的页眉对整个节有效

在标题样式上写header: { elements: [] },会让直到下一个带样式标题之前的页眉都消失,而不只是首页。只想让首页不出页眉,就给页眉元素加上pages: 'body'。 书眉与页码 →

  • 标题样式的header对该标题开启的整个节都有效,所以在文章标题上写header: { elements: [] },会让直到下一个带样式的标题之前的所有页面都没有页眉。要让第一页不出现页眉,在页眉元素上用pages: 'body'就够了。

致谢

文本
原创文字, CC BY 4.0
字体
PT Serif (SIL OFL 1.1) · Fira Sans (SIL OFL 1.1) · Fira Sans Condensed (SIL OFL 1.1)
沙盒PDF