How to refer subfigures using subpar and custom numbering

Hi everyone,

In my document, I use multiple times subpar to handle subfigures as follows:

#import "@preview/subpar:0.2.2"
#import "@preview/fancy-units:0.1.1": num, unit, qty, fancy-units-configure, add-macros

#subpar.grid(placement:auto,
  figure(
    table(
    columns: (1fr, 1fr, 1fr, 1fr),
    table.header(
      [Case study],
      [\# Nodes],
      [\# Interfaces],
      [\# Cells]
    ),
    [Toce], [6 716], [19 731], [12 996],
    [Toce _XL_], [406 115], [1 214 591], [808 457],
    [Square basin], [290 132], [868 393], [578 262],
  ) ,
    gap: .75em,
    caption: [
    Geometric description of meshes
  ],
  ), <meshes>,
  figure(
    table(
    columns: (1fr, 1fr, 1fr),
    table.header(
      [Parameter],
      [Toce],
      [Square basin],
    ),
    [$t_"start"$ [#unit[s]]], [7], [0],
    [$t_"end"$ [#unit[s]]], [60], [60],
    [$n$ [#unit[-]]], [0.0162], [0.06],
    [$sigma$ [#unit[-]]], [0.9], [0.95],
    [$Delta t_"pics"$ [#unit[s]]], [1], [1],
    [$Delta t_"gauges"$ [#unit[s]]], [1], [],
    [$Delta t_"sections"$ [#unit[s]]], [1], [],
    [$Delta t_"enveloppes"$ [#unit[s]]], [1], [1]
    ),
    gap: .75em,
    caption: [
    Simulation parameters
  ]), <simulations>,
  columns: 1,
  caption: [Case study descriptions],
  kind: table,
  numbering: n => {
    let h1 = counter(heading).get().first()
    numbering("1.1", h1, n)
  }, gap: 1em
)

as you can see I use custom numbering that aligns with headings. However, when referenced in the document, I got:

image

it does not respect the numbering. I tried to follow the procedure of Why do references to subfigures (using subpar) not respect custom numbering? but it didn’t work.

Is there a way to correct references ? And is there a way to set a rule such that my numbering is applied to all subpar figures without having to manually specify it ?
Thank you very much

Hi, the mentioned numbering-sub-ref parameter is correct, but because the sub figure has two levels your custom numbering doesn’t work. You have to capture both levels with a sink ..n:

...
numbering-sub-ref: (..n) => {
  let h1 = counter(heading).get().first()
  numbering("1.1a", h1, ..n)
}
...

I think the easiest is to use .with(…) to create and use a custom variable with the arguments preapplied.

#let mysubpar = subpar.grid.with(numbering: ..., numbering-sub-ref:...)

Hi. If the table content is not relevant, then you should remove it, it’s harder to work with big examples.

The what numbering? It includes the figure and sub-figure number, so it’s correct. To change the default reference styling, use How to refer subfigures using subpar and custom numbering - #2 by flokl, though a simpler version would be this:

  numbering-sub-ref: (..n) => {
    numbering("1.1a", ..counter(heading.where(level: 1)).get(), ..n)
  },

#import "@preview/subpar:0.2.2"

#set heading(numbering: "1.")

= Heading
= Heading
== Heading

@simulations

#subpar.grid(
  figure(rect(), caption: [Geometric description of meshes]),
  <meshes>,
  figure(rect(), caption: [Simulation parameters]),
  <simulations>,
  columns: 1,
  caption: [Case study descriptions],
  kind: table,
  numbering: n => {
    numbering("1.1", ..counter(heading.where(level: 1)).get(), n)
  },
  numbering-sub-ref: (..n) => {
    numbering("1.1a", ..counter(heading.where(level: 1)).get(), ..n)
  },
)

image


Regarding the tables, you can shorten some stuff:

#import "@preview/subpar:0.2.2"
#import "@preview/fancy-units:0.1.1": (
  add-macros,
  fancy-units-configure,
  num,
  qty,
  unit,
)

#subpar.grid(
  figure(
    table(
      columns: (1fr,) * 4,
      table.header[Case study][\# Nodes][\# Interfaces][\# Cells],
      [Toce], [6 716], [19 731], [12 996],
      [Toce _XL_], [406 115], [1 214 591], [808 457],
      [Square basin], [290 132], [868 393], [578 262],
    ),
    gap: 0.75em,
    caption: [Geometric description of meshes],
  ),
  <meshes>,
  figure(
    table(
      columns: (1fr,) * 3,
      table.header[Parameter][Toce][Square basin],
      [$t_"start"$ [#unit[s]]], [7], [0],
      [$t_"end"$ [#unit[s]]], [60], [60],
      [$n$ [#unit[-]]], [0.0162], [0.06],
      [$sigma$ [#unit[-]]], [0.9], [0.95],
      [$Delta t_"pics"$ [#unit[s]]], [1], [1],
      [$Delta t_"gauges"$ [#unit[s]]], [1], [],
      [$Delta t_"sections"$ [#unit[s]]], [1], [],
      [$Delta t_"enveloppes"$ [#unit[s]]], [1], [1],
    ),
    gap: 0.75em,
    caption: [Simulation parameters],
  ),
  <simulations>,
  columns: 1,
  caption: [Case study descriptions],
  kind: table,
  numbering: n => numbering("1.1", ..counter(heading.where(level: 1)).get(), n),
  numbering-sub-ref: (..n) => {
    numbering("1.1a", ..counter(heading.where(level: 1)).get(), ..n)
  },
  gap: 1em,
  placement: auto,
)