/
.table 函数接受一个块级参数,即一个由表格组成的可迭代对象 。该调用的结果是一张新表格,它将所提供表格按列组合在一起。
在下面的示例中,使用了 .repeat,它与其他受支持的循环 一样,将每次迭代的结果作为可迭代对象返回。
.table
.repeat {3}
n:
| Column .n |
|-----------|
| Cell .n:1 |
| Cell .n:2 |
| Cell .n:3 || Column 1 | Column 2 | Column 3 |
|---|---|---|
| Cell 1:1 | Cell 2:1 | Cell 3:1 |
| Cell 1:2 | Cell 2:2 | Cell 3:2 |
| Cell 1:3 | Cell 2:3 | Cell 3:3 |
.tablebyrows 文档 ↗ 函数接受两个参数:一个可选的表头可迭代对象,以及一个行可迭代对象。
.var {headers}
- Name
- Age
- City
.tablebyrows {.headers}
- - John
- 25
- NY
- - Lisa
- 32
- LA
- - Mike
- 19
- CHI| Name | Age | City |
|---|---|---|
| John | 25 | NY |
| Lisa | 32 | LA |
| Mike | 19 | CHI |
如果未提供表头,表格就不会有表头行。此外,也可以使用动态内容来生成单元格:
.tablebyrows
.repeat {3}
y:
.repeat {3}
x:
Cell .x:.y| Cell 1:1 | Cell 2:1 | Cell 3:1 |
| Cell 1:2 | Cell 2:2 | Cell 3:2 |
| Cell 1:3 | Cell 2:3 | Cell 3:3 |