|
| 1 | +#show figure: set block(breakable: true) |
| 2 | +#figure( // start preamble figure |
| 3 | + |
| 4 | + kind: "tinytable", |
| 5 | + supplement: "Table", // end preamble figure |
| 6 | + |
| 7 | +block[ // start block |
| 8 | + |
| 9 | + #let style-dict = ( |
| 10 | + // tinytable style-dict after |
| 11 | + "0_0": 0, "1_0": 0, "2_0": 0, "0_1": 0, "1_1": 0, "2_1": 0, "0_2": 0, "1_2": 0, "2_2": 0, "0_3": 0, "1_3": 0, "2_3": 0, "0_4": 0, "1_4": 0, "2_4": 0 |
| 12 | + ) |
| 13 | + |
| 14 | + #let style-array = ( |
| 15 | + // tinytable cell style after |
| 16 | + (align: center,), |
| 17 | + ) |
| 18 | + |
| 19 | + // Helper function to get cell style |
| 20 | + #let get-style(x, y) = { |
| 21 | + let key = str(y) + "_" + str(x) |
| 22 | + if key in style-dict { style-array.at(style-dict.at(key)) } else { none } |
| 23 | + } |
| 24 | + |
| 25 | + // tinytable align-default-array before |
| 26 | + #let align-default-array = ( left, left, left, left, left, ) // tinytable align-default-array here |
| 27 | + #show table.cell: it => { |
| 28 | + if style-array.len() == 0 { return it } |
| 29 | + |
| 30 | + let style = get-style(it.x, it.y) |
| 31 | + if style == none { return it } |
| 32 | + |
| 33 | + let tmp = it |
| 34 | + if ("fontsize" in style) { tmp = text(size: style.fontsize, tmp) } |
| 35 | + if ("color" in style) { tmp = text(fill: style.color, tmp) } |
| 36 | + if ("indent" in style) { tmp = pad(left: style.indent, tmp) } |
| 37 | + if ("underline" in style) { tmp = underline(tmp) } |
| 38 | + if ("italic" in style) { tmp = emph(tmp) } |
| 39 | + if ("bold" in style) { tmp = strong(tmp) } |
| 40 | + if ("mono" in style) { tmp = math.mono(tmp) } |
| 41 | + if ("strikeout" in style) { tmp = strike(tmp) } |
| 42 | + if ("smallcaps" in style) { tmp = smallcaps(tmp) } |
| 43 | + tmp |
| 44 | + } |
| 45 | + |
| 46 | + #align(center, [ |
| 47 | + |
| 48 | + #table( // tinytable table start |
| 49 | + column-gutter: 5pt, |
| 50 | + columns: (auto, auto, auto, auto, auto), |
| 51 | + stroke: none, |
| 52 | + rows: auto, |
| 53 | + align: (x, y) => { |
| 54 | + let style = get-style(x, y) |
| 55 | + if style != none and "align" in style { style.align } else { left } |
| 56 | + }, |
| 57 | + fill: (x, y) => { |
| 58 | + let style = get-style(x, y) |
| 59 | + if style != none and "background" in style { style.background } |
| 60 | + }, |
| 61 | + table.hline(y: 1, start: 0, end: 3, stroke: 0.05em + black), table.hline(y: 1, start: 3, end: 4, stroke: 0.05em + black), table.hline(y: 1, start: 3, end: 4, stroke: 0.05em + black), |
| 62 | + table.hline(y: 2, start: 0, end: 1, stroke: 0.05em + black), table.hline(y: 2, start: 0, end: 2, stroke: 0.05em + black), table.hline(y: 2, start: 2, end: 2, stroke: 0.05em + black), table.hline(y: 2, start: 1, end: 2, stroke: 0.05em + black), table.hline(y: 2, start: 2, end: 2, stroke: 0.05em + black), table.hline(y: 2, start: 2, end: 3, stroke: 0.05em + black), table.hline(y: 2, start: 2, end: 4, stroke: 0.05em + black), table.hline(y: 2, start: 3, end: 5, stroke: 0.05em + black), table.hline(y: 2, start: 4, end: 5, stroke: 0.05em + black), |
| 63 | + table.hline(y: 3, start: 1, end: 2, stroke: 0.05em + black), table.hline(y: 3, start: 1, end: 2, stroke: 0.05em + black), table.hline(y: 3, start: 1, end: 3, stroke: 0.05em + black), table.hline(y: 3, start: 3, end: 3, stroke: 0.05em + black), table.hline(y: 3, start: 3, end: 3, stroke: 0.05em + black), table.hline(y: 3, start: 2, end: 3, stroke: 0.05em + black), table.hline(y: 3, start: 3, end: 3, stroke: 0.05em + black), table.hline(y: 3, start: 3, end: 3, stroke: 0.05em + black), table.hline(y: 3, start: 2, end: 3, stroke: 0.05em + black), table.hline(y: 3, start: 3, end: 3, stroke: 0.05em + black), table.hline(y: 3, start: 3, end: 3, stroke: 0.05em + black), table.hline(y: 3, start: 3, end: 4, stroke: 0.05em + black), table.hline(y: 3, start: 3, end: 4, stroke: 0.05em + black), table.hline(y: 3, start: 3, end: 5, stroke: 0.05em + black), table.hline(y: 3, start: 4, end: 5, stroke: 0.05em + black), table.hline(y: 3, start: 4, end: 5, stroke: 0.05em + black), |
| 64 | + table.hline(y: 4, start: 0, end: 5, stroke: 0.05em + black), |
| 65 | + table.hline(y: 7, start: 0, end: 5, stroke: 0.1em + black), |
| 66 | + table.hline(y: 0, start: 0, end: 5, stroke: 0.1em + black), |
| 67 | + // tinytable lines before |
| 68 | + |
| 69 | + // tinytable header start |
| 70 | + table.header( |
| 71 | + repeat: true, |
| 72 | +table.cell(colspan: 3, align: center)[e], [f], [ ], |
| 73 | +table.cell(colspan: 2, align: center)[c], table.cell(colspan: 3, align: center)[d], |
| 74 | +[ ], table.cell(colspan: 2, align: center)[a], table.cell(colspan: 2, align: center)[b], |
| 75 | +[mpg], [cyl], [disp], [hp], [drat], |
| 76 | + ), |
| 77 | + // tinytable header end |
| 78 | + |
| 79 | + // tinytable cell content after |
| 80 | +[21.0], [6], [160], [110], [3.90], |
| 81 | +[21.0], [6], [160], [110], [3.90], |
| 82 | +[22.8], [4], [108], [93], [3.85], |
| 83 | + |
| 84 | + // tinytable footer after |
| 85 | + |
| 86 | + ) // end table |
| 87 | + |
| 88 | + ]) // end align |
| 89 | + |
| 90 | +] // end block |
| 91 | +) // end figure |
0 commit comments