How to reference styled figures?

@vmartel08’s solution works, but IMO you don’t actually need to write a ref show rule unless you’d like to keep the original label syntax.

A simpler approach by adding a label parameter to your sidefigure could look like this.

#sidefigure(
  rect(),
  caption: "Figure Caption",
  dy: -2em,
  label: <fig:1>
)

Some comments:

  • You don’t actually need to use so many context expressions. The only contextual statement is the counter display, so just preprend context to that!
  • Nested context can and will result in problems later on, especially if you have multiple show rules.
  • You can probably use a figure(kind: "sidefigure") and write your show rules separately in the template body on figure.where(kind: "sidefigure"), that would make the function sidefigure simpler to read, and modify.
#let sidefigure(content, caption: none, dy: -1.5em, label: none) = margin-note(
  {
    show figure.caption: it => [
      #set align(left)
      #let kind = none
      #if it.supplement.text.contains("Fig") {
        kind = image
      } else if it.supplement.text.contains("Tab") {
        kind = table
      }
      #it.supplement #context it.counter.display(it.numbering) #it.separator #it.body
    ]
    set figure.caption(position: bottom)
    [#figure(
      content,
      caption: caption,
    )#label]
  },
  dy: dy,
)

#show: template.with()

= Section 1

#lorem(50)

#sidefigure(
  rect(),
  caption: "Figure Caption",
  dy: -2em,
  label: <fig:1>
)

@fig:1
4 Likes