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

如何在Typst的grid中单独引用子figure

解决Typst中网格子图无法单独引用的问题

你遇到的核心问题是嵌套的figure不会被Typst的引用系统单独注册,外层figure会覆盖内层子figure的标签,导致无法单独引用子图。以下是两种可行的解决方法:

方法一:基础版(单独引用子图+子图标题)

直接在grid中用stack组合图片和子图标题,给每个图片添加独立标签,同时在外层figure的总标题中关联子图:

#figure(
  grid(
    columns: 2,
    grid.cell(
      stack(
        image("Pictures/PowerGeo.png", width:90%)<power-geo>,
        text(align: center, size: small, [a. 算术运算])
      )
    ),
    grid.cell(
      stack(
        image("Pictures/PowerMath.png", width:90%)<power-math>,
        text(align: center, size: small, [b. 几何运算])
      )
    ),
  ),
  caption: [两种运算类型:@power-geo(算术运算)和 @power-math(几何运算)],
)<power>

使用时:

  • 引用整个图:@power
  • 引用第一个子图:@power-geo
  • 引用第二个子图:@power-math

方法二:进阶版(带自动编号的子图)

如果需要子图带自动编号(比如“图1a”“图1b”),可以自定义计数器实现:

// 定义子图计数器
#let subfig-counter = counter("subfig")

#figure(
  grid(
    columns: 2,
    grid.cell(
      stack(
        image("Pictures/PowerGeo.png", width:90%)<power-geo>,
        text(align: center, size: small, [
          #counter("figure").display()#subfig-counter.display("a")
          . 算术运算
        ])
      ),
      // 递增子图计数器
      #subfig-counter.step()
    ),
    grid.cell(
      stack(
        image("Pictures/PowerMath.png", width:90%)<power-math>,
        text(align: center, size: small, [
          #counter("figure").display()#subfig-counter.display("a")
          . 几何运算
        ])
      ),
      #subfig-counter.step()
    ),
  ),
  caption: [两种运算类型展示],
  // 重置计数器,避免影响后续图
  #subfig-counter.reset()
)<power>

关键说明

  • 不要在figure内部嵌套figure:Typst只会识别最外层figure的标签,内层figure的标签不会被注册到引用系统。
  • 直接给图片或容器加标签:确保每个需要引用的子图元素都有独立的<tag>标识,这样就能通过@tag单独引用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 15:07:28