1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
// Test grid layouts.
--- grid-columns-sizings-rect ---
#let cell(width, color) = rect(width: width, height: 2cm, fill: color)
#set page(width: 100pt, height: 140pt)
#grid(
columns: (auto, 1fr, 3fr, 0.25cm, 3%, 2mm + 10%),
cell(0.5cm, rgb("2a631a")),
cell(100%, forest),
cell(100%, conifer),
cell(100%, rgb("ff0000")),
cell(100%, rgb("00ff00")),
cell(80%, rgb("00faf0")),
cell(1cm, rgb("00ff00")),
cell(0.5cm, rgb("2a631a")),
cell(100%, forest),
cell(100%, conifer),
cell(100%, rgb("ff0000")),
cell(100%, rgb("00ff00")),
)
--- grid-gutter-fr ---
#set rect(inset: 0pt)
#grid(
columns: (auto, auto, 40%),
column-gutter: 1fr,
row-gutter: 1fr,
rect(fill: eastern)[dddaa aaa aaa],
rect(fill: conifer)[ccc],
rect(fill: rgb("dddddd"))[aaa],
)
--- grid-row-sizing-manual-align ---
#set page(height: 3cm, margin: 0pt)
#grid(
columns: (1fr,),
rows: (1fr, auto, 2fr),
[],
align(center)[A bit more to the top],
[],
)
--- grid-finance ---
// Test using the `grid` function to create a finance table.
#set page(width: 11cm, height: 2.5cm)
#grid(
columns: 5,
column-gutter: (2fr, 1fr, 1fr),
row-gutter: 6pt,
[*Quarter*],
[Expenditure],
[External Revenue],
[Financial ROI],
[_total_],
[*Q1*],
[173,472.57 \$],
[472,860.91 \$],
[51,286.84 \$],
[_350,675.18 \$_],
[*Q2*],
[93,382.12 \$],
[439,382.85 \$],
[-1,134.30 \$],
[_344,866.43 \$_],
[*Q3*],
[96,421.49 \$],
[238,583.54 \$],
[3,497.12 \$],
[_145,659.17 \$_],
)
// Test grid cells that overflow to the next region.
--- grid-cell-breaking ---
#set page(width: 5cm, height: 3cm)
#grid(
columns: 2,
row-gutter: 8pt,
[Lorem ipsum dolor sit amet.
Aenean commodo ligula eget dolor. Aenean massa. Penatibus et magnis.],
[Text that is rather short],
[Fireflies],
[Critical],
[Decorum],
[Rampage],
)
--- grid-consecutive-rows-breaking ---
// Test a column that starts overflowing right after another row/column did
// that.
#set page(width: 5cm, height: 2cm)
#grid(
columns: 4 * (1fr,),
row-gutter: 10pt,
column-gutter: (0pt, 10%),
align(top, image("/assets/images/rhino.png")),
align(top, rect(inset: 0pt, fill: eastern, align(right)[LoL])),
[rofl],
[\ A] * 3,
[Ha!\ ] * 3,
)
--- grid-same-row-multiple-columns-breaking ---
// Test two columns in the same row overflowing by a different amount.
#set page(width: 5cm, height: 2cm)
#grid(
columns: 3 * (1fr,),
row-gutter: 8pt,
column-gutter: (0pt, 10%),
[A], [B], [C],
[Ha!\ ] * 6,
[rofl],
[\ A] * 3,
[hello],
[darkness],
[my old]
)
--- grid-nested-breaking ---
// Test grid within a grid, overflowing.
#set page(width: 5cm, height: 2.25cm)
#grid(
columns: 4 * (1fr,),
row-gutter: 10pt,
column-gutter: (0pt, 10%),
[A], [B], [C], [D],
grid(columns: 2, [A], [B], [C\ ]*3, [D]),
align(top, rect(inset: 0pt, fill: eastern, align(right)[LoL])),
[rofl],
[E\ ]*4,
)
--- grid-column-sizing-auto-base ---
// Test that auto and relative columns use the correct base.
#grid(
columns: (auto, 60%),
rows: (auto, auto),
rect(width: 50%, height: 0.5cm, fill: conifer),
rect(width: 100%, height: 0.5cm, fill: eastern),
rect(width: 50%, height: 0.5cm, fill: forest),
)
--- grid-column-sizing-fr-base ---
// Test that fr columns use the correct base.
#grid(
columns: (1fr,) * 4,
rows: (1cm,),
rect(width: 50%, fill: conifer),
rect(width: 50%, fill: forest),
rect(width: 50%, fill: conifer),
rect(width: 50%, fill: forest),
)
--- grid-column-sizing-mixed-base ---
// Test that all three kinds of rows use the correct bases.
#set page(height: 4cm, margin: 0cm)
#grid(
rows: (1cm, 1fr, 1fr, auto),
rect(height: 50%, width: 100%, fill: conifer),
rect(height: 50%, width: 100%, fill: forest),
rect(height: 50%, width: 100%, fill: conifer),
rect(height: 25%, width: 100%, fill: forest),
)
--- grid-trailing-linebreak-region-overflow ---
// Test that trailing linebreak doesn't overflow the region.
#set page(height: 2cm)
#grid[
Hello \
Hello \
Hello \
World
]
--- grid-breaking-expand-vertically ---
// Test that broken cell expands vertically.
#set page(height: 2.25cm)
#grid(
columns: 2,
gutter: 10pt,
align(bottom)[A],
[
Top
#align(bottom)[
Bottom \
Bottom
Top
]
],
align(top)[B],
)
--- grid-complete-rows ---
// Ensure grids expand enough for the given rows.
#grid(
columns: (2em, 2em),
rows: (2em,) * 4,
fill: red,
stroke: aqua,
[a]
)
--- grid-auto-shrink ---
// Test iterative auto column shrinking.
#set page(width: 210mm - 2 * 2.5cm + 2 * 10pt)
#set text(11pt)
#table(
columns: 4,
[Hello!],
[Hello there, my friend!],
[Hello there, my friends! Hi!],
[Hello there, my friends! Hi! What is going on right now?],
)
--- issue-grid-base-auto-row ---
// Test that grid base for auto rows makes sense.
#set page(height: 150pt)
#table(
columns: (1.5cm, auto),
rows: (auto, auto),
rect(width: 100%, fill: red),
rect(width: 100%, fill: blue),
rect(width: 100%, height: 50%, fill: green),
)
--- issue-grid-base-auto-row-list ---
#rect(width: 100%, height: 1em)
- #rect(width: 100%, height: 1em)
- #rect(width: 100%, height: 1em)
--- issue-grid-skip ---
// Grid now skips a remaining region when one of the cells
// doesn't fit into it at all.
#set page(height: 100pt)
#grid(
columns: (2cm, auto),
rows: (auto, auto),
rect(width: 100%, fill: red),
rect(width: 100%, fill: blue),
rect(width: 100%, height: 80%, fill: green),
[hello \ darkness #parbreak() my \ old \ friend \ I],
rect(width: 100%, height: 20%, fill: blue),
polygon(fill: red, (0%, 0%), (100%, 0%), (100%, 20%))
)
--- issue-grid-skip-list ---
#set page(height: 60pt)
#lines(2)
- #lines(2)
--- issue-grid-double-skip ---
// Ensure that the list does not jump to the third page.
#set page(height: 70pt)
#v(40pt)
The following:
+ A
+ B
--- issue-grid-gutter-skip ---
// Ensure gutter rows at the top or bottom of a region are skipped.
#set page(height: 10em)
#table(
row-gutter: 1.5em,
inset: 0pt,
rows: (1fr, auto),
[a],
[],
[],
[f],
[e\ e],
[],
[a]
)
--- issue-3917-grid-with-infinite-width ---
// https://github.com/typst/typst/issues/1918
#set page(width: auto)
#context layout(available => {
let infinite-length = available.width
// Error: 3-50 cannot create grid with infinite width
grid(gutter: infinite-length, columns: 2)[A][B]
})
|