How to fix numbering with subpar and i-figured

Reference this issue:

And the code in issue:

#import "@preview/subpar:0.2.2"
// import the package
#import "@preview/i-figured:0.2.4"
#set page(height: auto)

// make sure you have some heading numbering set
#set heading(numbering: "1.")

// apply the show rules (these can be customized)
#show heading: i-figured.reset-counters
#show figure: i-figured.show-figure

= First
#subpar.grid(
  figure([A], caption: [
   A
  ]), <a>,
  figure([B], caption: [
   B
  ]), <b>,
  columns: (1fr, 1fr),
  caption: [A and B.]
)

We get unwanted numbering for sub figures(the number should be a, and b, but we get b and d).


I have also checked that use i-figured only will also have the problem:

#import "@preview/i-figured:0.2.4"
#set page(height: auto)

#set heading(numbering: "1.")

#show heading: i-figured.reset-counters
#show figure: i-figured.show-figure


= Ch1

#figure(
  grid(
    columns: 2,
    figure([#lorem(8)], caption: "(a)", numbering: none),
    figure([#lorem(8)], caption: "(b)", numbering: none)
  ),
  caption: ["Figure with two sub-figures"]
)

The output:

The desired output should be something like this(Please ignore the Figure 1 mismatch):

I’m not entirely sure, but I think the issue is that the i-figured package creates a new figure inside a function used with show figure: .... This leads to a figure inside a figure that messes with the counter used by subpar.

I grabbed the numbering-by-section code from @Andrew `s answer in the Typst issue #1896 and made a quick example with working sub figure numbering.

#import "@preview/subpar:0.2.2"

#set heading(numbering: "1.1")

#set math.equation(numbering: (..num) =>
  numbering("(1.1)", counter(heading).get().first(), num.pos().first())
)
#set figure(numbering: (..num) =>
  numbering("1.1", counter(heading).get().first(), num.pos().first()),
)
#show heading.where(level: 1): it => {
  counter(math.equation).update(0)
  counter(figure.where(kind: image)).update(0)
  counter(figure.where(kind: table)).update(0)
  counter(figure.where(kind: raw)).update(0)
  it
}

#let my-subpar(..args) = subpar.grid(
  numbering: (..num) => numbering("1.1", counter(heading).get().first(), num.pos().first()),
  numbering-sub-ref: (..num) => numbering("1.1a", counter(heading).get().first(), ..num),
  outlined-sub: true,
  ..args
)

= First

#my-subpar(
  figure([A], caption: [
   A
  ]), <a>,
  figure([B], caption: [
   B
  ]), <b>,
  columns: (1fr, 1fr),
  caption: [A and B.],
  label: <my-fig>
) 

@my-fig

@a

@b

1 Like

You can consider switching to the hallon package.

It does both subfigures and and figure numbering per chapter well.

#import "@preview/hallon:0.1.3" as hallon: subfigure
#show: hallon.style-figures.with(heading-levels: 1)

= Chapter 1
#let example-fig = rect(fill: aqua)
#figure(
	grid(
		columns: 2,
		subfigure(
			example-fig,
			caption: [foo],
			label: <subfig1-foo>,
		),
		subfigure(
			example-fig,
			caption: [bar],
			label: <subfig1-bar>,
		),
	),
	gap: 1em,
	caption: lorem(5),
)
1 Like

I just realized that this can benefit from that split arg trick, so I updated the comment.

#set math.equation(numbering: (n, ..) => {
  numbering("(1.1)", counter(heading).get().first(), n)
})
#set figure(numbering: (n, ..) => {
  numbering("1.1", counter(heading).get().first(), n)
})

Though until we get more sophisticated equation/figure numberings, this is enough for these elements:

#set figure(numbering: n => numbering("1.1", counter(heading).get().first(), n))
3 Likes