注意 / 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+后期随缘更新

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

Arranges content in a grid.

The grid element allows you to arrange content in a grid. You can define the number of rows and columns, as well as the size of the gutters between them. There are multiple sizing modes for columns and rows that can be used to create complex layouts.

The sizing of the grid is determined by the track sizes specified in the arguments. Because each of the sizing parameters accepts the same values, we will explain them just once, here. Each sizing argument accepts an array of individual track sizes. A track size is either:

  • auto: The track will be sized to fit its contents. It will be at most as large as the remaining space. If there is more than one auto track which, and together they claim more than the available space, the auto tracks will fairly distribute the available space among themselves.

  • A fixed or relative length (e.g. 10pt or 20% - 1cm): The track will be exactly of this size.

  • A fractional length (e.g. 1fr): Once all other tracks have been sized, the remaining space will be divided among the fractional tracks according to their fractions. For example, if there are two fractional tracks, each with a fraction of 1fr, they will each take up half of the remaining space.

To specify a single track, the array can be omitted in favor of a single value. To specify multiple auto tracks, enter the number of tracks instead of an array. For example, columns: 3 is equivalent to columns: (auto, auto, auto).

Examples

The example below demonstrates the different track sizing options.

// We use `rect` to emphasize the
// area of cells.
#set rect(
  inset: 8pt,
  fill: rgb("e4e5ea"),
  width: 100%,
)

#grid(
  columns: (60pt, 1fr, 2fr),
  rows: (auto, 60pt),
  gutter: 3pt,
  rect[Fixed width, auto height],
  rect[1/3 of the remains],
  rect[2/3 of the remains],
  rect(height: 100%)[Fixed height],
  image("tiger.jpg", height: 100%),
  image("tiger.jpg", height: 100%),
)
Preview

You can also spread an array of strings or content into a grid to populate its cells.

#grid(
  columns: 5,
  gutter: 5pt,
  ..range(25).map(str)
)
Preview

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

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

The column sizes.

Either specify a track size array or provide an integer to create a grid with that many auto-sized columns. Note that opposed to rows and gutters, providing a single track size will only ever create a single column.

默认值:

()

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

The row sizes.

If there are more cells than fit the defined rows, the last row is repeated until there are no more cells.

默认值:

()

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

The gaps between rows & columns.

If there are more gutters than defined sizes, the last gutter is repeated.

默认值:

()

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

The gaps between columns. Takes precedence over gutter.

默认值:

()

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

The gaps between rows. Takes precedence over gutter.

默认值:

()

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

The contents of the grid cells.

The cells are populated in row-major order.

转到官方文档(英文)

搜索