Figure and table captions with chapter number

Hi,

I managed to create a demo on using counters to display figure and table captions with numbering. Here is the link:

https://typst.app/project/rHVlsLUqcZ5zRT26hUfZFB

I paste the code here too

#set heading(numbering: "1.")
#let fig = counter("figure")
#let tab = counter("table")

#let fig_numbering(.., desc) = {
  fig.step()
  context str(counter(heading).get().at(0)) + "-" + context fig.display()
}

#let tab_numbering(.., desc) = {
  tab.step()
  context str(counter(heading).get().at(0)) + "-" + context tab.display()
}

#show figure.where(
  kind: table
): set figure.caption(position: top)


= Introduction

== Background

The current value is: #context counter(heading).display() \
Heading 1 value = #context counter(heading).get().at(0) \
Heading 1 in roman numerals: #context counter(heading).display("I")

#figure(
  image("circles.png"),
  caption: "Drawing circles in AutoCAD",
  numbering: fig_numbering
)

#figure(
  table(
    columns: 4,
    [t], [1], [2], [3],
    [y], [0.3s], [0.4s], [0.8s],
  ),
  caption: [Timing results],
  numbering: tab_numbering
)

== More Background

#figure(
  image("circles.png"),
  caption: "Drawing circles in AutoCAD",
  numbering: fig_numbering
)

= Theory
#counter("figure").update(0)
#counter("table").update(0)

== More Theory

#figure(
  image("circles.png"),
  caption: "Drawing circles in AutoCAD",
  numbering: fig_numbering
)

#figure(
  table(
    columns: 4,
    [t], [1], [2], [3],
    [y], [0.3s], [0.4s], [0.8s],
  ),
  caption: [Timing results],
  numbering: tab_numbering
)

2 Likes

If you start your code block with ```typst then it will have proper syntax highlighting. So the following block

```typst
#set text(weight: "bold")
This text is bold
```

will be rendered as

#set text(weight: "bold")
This text is bold

EDIT
At a second glance I figure you used a quote instead of a codeblock. Please prefer code blocks for actual code as it makes it easier for people to read. Especially if you use some indents for blocks of code.

You accidentally included the image in the codeblock.

1 Like