Skip to content

Style of a table's cell based on the content of another cel? #4555

Answered by frozolotl
jolitp asked this question in Q&A
Discussion options

You must be logged in to vote

You can't (easily) use a show rule here, but you can instead input the cells pre-colored:

#let data = (
  ("one", "one"),
  ("one", "two"),
)
#table(
  columns: 3,
  table.header[*n*][*exp.*][*result*],
  ..data
    .enumerate(start: 1)
    .map(((n, (left, right))) => {
      let cell = table.cell.with(fill: if left == right { green } else { red })
      (cell[#n], cell(left), cell(right))
    })
    .flatten(),
)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jolitp
Comment options

Answer selected by jolitp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants