Replies: 1 comment
-
#let dictify-sides(v) = if dictionary == type(v) and "top" in v {
// `"top"` always present in side-dicts because of auto-normalization
v
} else {(
rest: v,
)}
#let dim-alignms(..args) = {
(:) + for alignm in args.pos() {
if alignm in ({}, auto) {} else if dictionary == type(alignm) {
for (k, v) in alignm {
let dim = dim-alignms(v)
if k in dim {((k): dim.at(k))}
}
} else if {} == alignm.axis() {
dim-alignms(alignm.x, alignm.y)
} else {(
("xy".at(int("vertical" == alignm.axis()))): alignm,
)}
}
}
#let add-alignms(..args) = {
let dims = dim-alignms(..args)
if (:) == dims {auto} else {dims.values().sum()}
}
= Conditional Inset
#context table(
columns: 2,// * (1fr,),
inset: (x, _)=> if 0 == x {(
rest: 0pt,
)} else {dictify-sides(table.inset)},
align: (x, _)=> add-alignms(
table.align,
if 0 == x {center},
),
)[A A\ a][B][C C\ c][DD]
= Alternative Approach
#import table: cell
#import calc: *
#import datetime: *
#let gen-double-row(stamp, descr, info) = (
..(stamp.display().split(" ") + 2 * ("",)).slice(0, 2),
cell(rowspan: 2, info),
cell(colspan: 2, descr),
)
#context table(
columns: 3,// * (1fr,),
inset: (x, _)=> dictify-sides(table.inset) + if 1 == x {(left: 0pt)},
stroke: (x, y)=> dictify-sides(table.stroke) + if 2 > x {(
(if odd(y) {"top"} else {"bottom"}): {},
(if odd(x) {"left"} else {"right"}): {},
)},
align: (x, y)=> add-alignms(
table.align,
if 1 < x {} else if odd(y) {center} else if even(x) {left} else {right},
),
fill: (x, y)=> table.fill + if 2 > x and even(y) {gray},
..gen-double-row(datetime(
year: 2024,
month: 5,
day: 5,
hour: 5,
minute: 5,
second: 5,
))[a][B],
..gen-double-row(datetime(
year: 2024,
month: 4,
day: 4,
hour: 4,
minute: 4,
second: 4,
))[c][DD],
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In a table, I want one column to have 0 inset to make cells with text that have grey background, and that only at the top. For that I'm using the following approach:
The problem is, the table has an inset of 6pt, but I want that background to go to the edges, so as I am currently seeing I would have to set the inset of the table to 0 and then wrap all elements in
Is that true? Or is there something better I can do here/maybe reverse the inset I set for the table just for that one column?
Beta Was this translation helpful? Give feedback.
All reactions