/

表格生成

按列生成表格

.table 函数接受一个块级参数,即一个由表格组成的可迭代对象 。该调用的结果是一张新表格,它将所提供表格按列组合在一起。

在下面的示例中,使用了 .repeat,它与其他受支持的循环 一样,将每次迭代的结果作为可迭代对象返回。

示例 1

.table
    .repeat {3}
        n:
        | Column .n |
        |-----------|
        | Cell .n:1 |
        | Cell .n:2 |
        | Cell .n:3 |
Column 1Column 2Column 3
Cell 1:1Cell 2:1Cell 3:1
Cell 1:2Cell 2:2Cell 3:2
Cell 1:3Cell 2:3Cell 3:3

按行生成表格

.tablebyrows 文档 ↗ 函数接受两个参数:一个可选的表头可迭代对象,以及一个行可迭代对象。

示例 2

.var {headers}
   - Name
   - Age
   - City

.tablebyrows {.headers}
    - - John
      - 25
      - NY
    - - Lisa
      - 32
      - LA
    - - Mike
      - 19
      - CHI
NameAgeCity
John25NY
Lisa32LA
Mike19CHI

示例 3

如果未提供表头,表格就不会有表头行。此外,也可以使用动态内容来生成单元格:

.tablebyrows
    .repeat {3}
        y:
        .repeat {3}
            x:
            Cell .x:.y
Cell 1:1Cell 2:1Cell 3:1
Cell 1:2Cell 2:2Cell 3:2
Cell 1:3Cell 2:3Cell 3:3