注意 / Info
本站经 Typst GmbH 许可,提供 Typst v0.10.0+后期随缘更新 官方文档的翻译,由中文社区维护。建议与官方文档一同阅读,因为可能存在错译、漏译或过时信息。如有意改进翻译内容或网站本身,可在GitHub上提出 Issue、发起 Pull Requests。此外,也欢迎加入「Typst 非官方中文交流群」(QQ 793548390)
This site provides a Chinese translation of the Typst v0.10.0+后期随缘更新 documentation maintained by the “Typst Chinese Community” with permission from Typst GmbH. We recommend using this alongside the official documentation. We welcome contributions through Issues and Pull Requests on our GitHub repository for both translation improvements and website enhancements. Feel free to join our QQ chat group “Typst 非官方中文交流群” (793548390).
Typst文档简体中文版
v0.10.0+后期随缘更新

table
元素
元素
元素函数可用setshow规则自定义样式。

A table of items.

Tables are used to arrange content in cells. Cells can contain arbitrary content, including multiple paragraphs and are specified in row-major order. Because tables are just grids with configurable cell properties, refer to the grid documentation for more information on how to size the table tracks.

To give a table a caption and make it referenceable, put it into a figure.

Example

#table(
  columns: (1fr, auto, auto),
  inset: 10pt,
  align: horizon,
  [], [*Area*], [*Parameters*],
  image("cylinder.svg"),
  $ pi h (D^2 - d^2) / 4 $,
  [
    $h$: height \
    $D$: outer radius \
    $d$: inner radius
  ],
  image("tetrahedron.svg"),
  $ sqrt(2) / 12 a^3 $,
  [$a$: edge length]
)
Preview

参数
参数
参数是传给函数的输入,写在函数名后的括号中。

columns
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

The column sizes. See the grid documentation for more information on track sizing.

默认值:

()

rows
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

The row sizes. See the grid documentation for more information on track sizing.

默认值:

()

gutter
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

The gaps between rows & columns. See the grid documentation for more information on gutters.

默认值:

()

column-gutter
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

The gaps between columns. Takes precedence over gutter. See the grid documentation for more information on gutters.

默认值:

()

row-gutter
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

The gaps between rows. Takes precedence over gutter. See the grid documentation for more information on gutters.

默认值:

()

fill
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

How to fill the cells.

This can be a color or a function that returns a color. The function is passed the cells' column and row index, starting at zero. This can be used to implement striped tables.

默认值:

none

展开例子
#table(
  fill: (col, _) => if calc.odd(col) { luma(240) } else { white },
  align: (col, row) =>
    if row == 0 { center }
    else if col == 0 { left }
    else { right },
  columns: 4,
  [], [*Q1*], [*Q2*], [*Q3*],
  [Revenue:], [1000 €], [2000 €], [3000 €],
  [Expenses:], [500 €], [1000 €], [1500 €],
  [Profit:], [500 €], [1000 €], [1500 €],
)
Preview

align
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

How to align the cells' content.

This can either be a single alignment, an array of alignments (corresponding to each column) or a function that returns an alignment. The function is passed the cells' column and row index, starting at zero. If set to auto, the outer alignment is used.

默认值:

auto

展开例子
#table(
  columns: 3,
  align: (x, y) => (left, center, right).at(x),
  [Hello], [Hello], [Hello],
  [A], [B], [C],
)
Preview

stroke
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

How to stroke the cells.

Strokes can be disabled by setting this to none.

Note: Richer stroke customization for individual cells is not yet implemented, but will be in the future. In the meantime, you can use the third-party tablex library.

默认值:

1pt + black

inset
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

How much to pad the cells' content.

默认值:

5pt

展开例子
#table(
  inset: 10pt,
  [Hello],
  [World],
)

#table(
  columns: 2,
  inset: (
    x: 20pt,
    y: 10pt,
  ),
  [Hello],
  [World],
)
Preview

children
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。
变长参数
变长参数
变长参数可以传入多次。

The contents of the table cells.

转到官方文档(英文)

搜索