You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Typst新手求助:带右侧Logo的蓝色页眉左右边距问题

解决Typst页眉蓝色Box左右边距问题

你的问题出在默认的header区域受页面margin限制,设置width:100%只会占满header的可用范围(margin内区域),因此左右会留下边距。以下是两种解决方案:

方案一:固定数值适配

直接针对当前margin值调整box位置和宽度:

#set page(
  margin: (top: 2.5cm, bottom: 2.5cm, left: 2.5cm, right: 2.5cm),
  header: box(
    width: page().width, // 设为整个页面宽度
    height: 2.5cm, // 与顶部margin高度一致,填满页眉
    fill: blue,
    x: -2.5cm, // 向左偏移抵消左侧margin,让box对齐页面左边缘
    content: place(right + horizon, inset: 2.5cm)[MYLOGO #h(1cm)]
  )
)

Hello World

方案二:通用适配(推荐)

通过变量引用margin值,后续修改margin时无需调整其他代码:

#set page(
  let page-margin = (top: 2.5cm, bottom: 2.5cm, left: 2.5cm, right: 2.5cm)
  margin: page-margin,
  header: box(
    width: page().width,
    height: page-margin.top,
    fill: blue,
    x: -page-margin.left,
    content: place(right + horizon, inset: page-margin.right)[MYLOGO #h(1cm)]
  )
)

Hello World

关键调整说明:

  • width: page().width:让蓝色Box宽度覆盖整个页面
  • x: -page-margin.left:向左偏移Box,抵消页面左侧margin,消除左边距
  • inset: page-margin.right:让Logo与页面右侧保持和margin一致的间距,避免贴边

内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 11:05:08