Hi. I see that you’ve created (basically) a duplicate of How to fill the first row of a table with a color?. There is no need to do that, you can just continue the conversation there. Although, at this point, might as well continue here. :)
Currently, some show/set rules for table stuff do not work, I think show: table.cell: set table.cell
is one of them (show heading: set heading
, for example, works). But regardless of that, You should always prefer the use of set rules or show-set rules over a show rule with a closure, because the latter creates a wrapper over the selected element (table.cell
in this example), which make it harder or impossible to modify the styling later. If set or show-set (or set-if) rules are not powerful enough for your use case, then of course you should use show rule to override the way an element is displayed.
In How to fill the first row of a table with a color? - #2 by quachpas you can actually use 1 set rule and 1 show-set rule instead:
#set table(fill: (_, y) => if y == 0 { gray })
#show table.cell.where(y: 0): set text(weight: "bold")
#table(
columns: 3, // equivalent to (auto, auto, auto)
[123], [1123], [1176],
[657], [5643], [4567],
[4567], [8970], [234],
)
Note that sometimes you might prefer strong
over set text(weight: "bold")
, but it’s very nuanced, and depends on the use case.
This way you can later undo those settings by writing
#set table(fill: none)
#show table.cell.where(y: 0): set text(weight: "regular")
Currently, there is no support for revoking rules yet, but if you just want to use the styling for a single table, then you can either use it directly when creating a table, or wrap it all in a new scope:
#{
set table(fill: (_, y) => if y == 0 { gray })
show table.cell.where(y: 0): set text(weight: "bold")
table(
columns: 3, // equivalent to (auto, auto, auto)
[123], [1123], [1176],
[657], [5643], [4567],
[4567], [8970], [234],
)
}
Again, overusing show rules is generally discouraged, but now one will stop you from using it. It just can make the setup look less readable, less flexible and introduce some issues down the road. But if it works, it works.
I should also point out that if your table has a header (and not just raw data), then it is advised to use table.header
(e.g., table.header[name][name][name]
) to provide better accessibility support as well as ability to use show table.header: strong
, both in the future,
P.S. If you find an answer to your question in any of the previous or future posts, please mark that specific message (with an answer) as the answer. It helps others quickly find what they are looking for.