#How can i color the first row of cells without using the fill attribute of the table?

18 messages · Page 1 of 1 (latest)

torpid galleon
#

I want to achieve the following:
Create one function that controls all the styling of my cells

When i try to alter the style of my cell with:
#show table.cell: cell => {
if cell.y == 0 {
set table.cell(fill: red)
strong(cell)
}else{
cell
}
}

The strong styling works as expected, but the fill is not working.
I assume that might be the case as the style is set while already being in the scope of the cell, that way the cell remains unaffected.
But how can i achieve the desired result?
Than you for your help

wanton minnow
#

maybe I'm dodging the question, but you can use fill: (y,x) => {if(y == 0){red}else{white}}

wise zealot
#

set rules don't match the base element of a show rule—except for show …: set rules. But—due to some bug—the idiomatic show cell.where(y: 0): set cell(…) also doesn't have an impact.

torpid galleon
#

That is unfortunate. I wanted to style the first row of every table in the document, but does not seem realizable.

tardy night
#

?r ps=a t=l

#set page(width: 300pt)

#let ftable(..args) = {
  table(
    fill: (x, y) => if y == 0 { green.lighten(75%) },
    ..args
  )
}

#ftable(
  columns: (1fr,) * 2,
  lorem(2),
  lorem(2),
  lorem(2),
  lorem(2)
)
tardy night
#

?r ps=a t=l

#set page(width: 300pt)

#let my-func() = {
  set table(fill: (x, y) => if y == 0 { green.lighten(75%) })

  table(
    columns: (1fr,) * 2,
    lorem(2),
    lorem(2),
    lorem(2),
    lorem(2),
  )
}

#my-func()

#table(
  columns: (1fr,) * 2,
  lorem(2),
  lorem(2),
  lorem(2),
  lorem(2),
)
torpid galleon
#

I arrived at a similar solution to yours:
#set table(fill: (x,y) => if y == 0 { silver })

But i still think there should be a way to change the fill with a cell style.

For example, why is this not working?
#show table.cell: c => {
if(c.y == 0) {
set text(weight: "bold")
set table.cell(fill: red)
table.cell(inset: 0.18cm)[#c.body]
} else {
c
}
}

tardy night
autumn elbow
#

The show rule also applies to the table.cell you created

#

But as low said, ideally you'd be able to use show-set rules for this

#

However that's not currently implemented, unfortunately

#

It will take a bit before it's there

#

But it's planned

wise zealot