How to correctly format the heading number and figure number in the figure's caption?

The header number and figure in the figure’s caption are badly formatted. For heading 1 and figure 1, the caption is as follows
Figure 1 . 1: some text
Problem: There is a space between the heading and the dot, then a space between the dot and the figure’s number.
My typ code is:

#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge

#outline()
#set heading(numbering: "1")

= Introduction

#show figure.caption: it => {
  [#it.supplement #context counter(heading).get().at(0) #[.] #it.numbering #it.separator#it.body]
}

#figure(
  table(
    columns: 2,
    align: (left, left),
    [row 1_1], [row 1_1],
    [row 2_1], [row 2_1],
  ),
  caption: [Caputred table_1]
)
\
#figure(
  diagram(
      node-fill: orange.lighten(60%),
      node-stroke: orange.lighten(20%),
      (
        node((0,0), [], shape: rect, width: 43mm, height: 7mm),
        node((0,0.38), [], shape: rect, width: 43mm, height: 7mm),
        )
    ),
    kind: image,
    caption: [Caputred nodes_1]
)

= History

#figure(
  table(
    columns: 2,
    align: (left, left),
    [row 1_1], [row 1_1],
    [row 2_1], [row 2_1],
  ),
  caption: [Caputred table_2]
)
\
#figure(
  diagram(
      node-fill: orange.lighten(60%),
      node-stroke: orange.lighten(20%),
      (
        node((0,0), [], shape: rect, width: 43mm, height: 7mm),
        node((0,0.38), [], shape: rect, width: 43mm, height: 7mm),
        )
    ),
    kind: image,
    caption: [Caputred nodes_2]
)

Problem solved, the show rule was not correct, the solution is as follows

#show figure.caption: it => {
  [#it.supplement #context counter(heading).get().at(0)#[.]#it.numbering #it.separator#it.body]
}

Sorry I made the wrong change, the problem is not solved.

The value of #it.numbering will always be "1". You would also need to access the figure counter to get the correct number.

I would recommend you to look at the package headcount – Typst Universe which has already solved your problem.

#import "@preview/headcount:0.1.0": dependent-numbering, reset-counter

#set heading(numbering: "1")

// set figure counter so that it inherits 1 level from heading
#set figure(numbering: dependent-numbering("1.1"))
#show heading: reset-counter(counter(figure.where(kind: image)))

= A title 
#figure(rect(), caption: lorem(10))
#figure(rect(), caption: lorem(10))
1 Like

Thank you for your support.