How can I create two differently formatted, reusable types of table?

Hi, I am currently trying to create two different specially styled tables. One with e.g. all text in bold for all cells and one with e.g. no visible strokes.
Throughout the document I want to reuse these styles for some tables.
How could I implement this?
Kind regards,
Kapati

Here are two different ways to do it. We can define functions - #bold-table() and #no-stroke-table() that are wrappers for table.

You can also style tables without wrapping them in functions and marking them by labels instead. The same label can be applied to one or more tables.

The two tables in the example look like this:

bild

These are prototypes - first implement the styles you want

#let headers = ([A], [B])
#let data = range(4).map(str)
#let hrule = table.hline(stroke: 0.08em)

#{
show table: set text(weight: "bold")
table(
  columns: 2,
  stroke: (x, y) => if y == 0 { (top: 0.08em, bottom: 0.04em) } else { none },
  table.header(..headers),
  ..data,
  hrule
)
}

#table(
  columns: 2,
  stroke: none,
  table.header(..headers),
  ..data,
)

---

Finished versions: using functions - translate the style into functions

#let bold-table(..args) = {
  show table: set text(weight: "bold")
  table(
    stroke: (x, y) => if y == 0 { (top: 0.08em, bottom: 0.04em) } else { none },
    ..args
  )
}
#let no-stroke-table = table.with(stroke: none)

#bold-table(
  columns: 2,
  table.header(..headers),
  ..data,
  hrule
)

#no-stroke-table(
  columns: 2,
  table.header(..headers),
  ..data
)

---

Finished versions - using labels to set style

#show <bold-table>: set text(weight: "bold")
#show <bold-table>: set table(stroke: (x, y) => if y == 0 { (top: 0.08em, bottom: 0.04em) } else { none })

#show <no-stroke-table>: set table(stroke: none)

#table(
  columns: 2,
  table.header(..headers),
  ..data,
  hrule
)<bold-table>


#table(
  columns: 2,
  table.header(..headers),
  ..data
)<no-stroke-table>
1 Like

Hi @Kapati, thanks for your question! If you feel the response you got has sufficiently answered your question, be sure to give it a checkmark :ballot_box_with_check:. This will help others find the solution in the future. If something is missing, please let us know what so we can resolve your issue. Thanks!