提示:本教程存在过时问题,更详细教程请阅读 小蓝书Typst 中文社区导航 FAQ
注意:该中文文档为社区驱动的非官网文档,可能存在错译、漏译或过时等问题,请以官网文档 Documentation 为准,如发现错漏,也欢迎 您的贡献镜像)。Typst 非官方中文交流 QQ 群:793548390
Warning: the Chinese document is a community-driven non-official document, there may be mistranslation, omission or outdated problems, please refer to the official website documentation.
Typst 中文文档

stack 元素
元素函数可以通过 set 和 show 规则进行样式自定义。

Arranges content and spacing horizontally or vertically.

The stack places a list of items along an axis, with optional spacing between each item.

Example

#stack(
  dir: ttb,
  rect(width: 40pt),
  rect(width: 120pt),
  rect(width: 90pt),
)
Preview

参数
参数是函数的输入,它们在函数名称后面的括号中传入。

dir
direction
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

The direction along which the items are stacked. Possible values are:

You can use the start and end methods to obtain the initial and final points (respectively) of a direction, as alignment. You can also use the axis method to determine whether a direction is "horizontal" or "vertical". The inv method returns a direction's inverse direction.

For example, ttb.start() is top, ttb.end() is bottom, ttb.axis() is "vertical" and ttb.inv() is equal to btt.

默认:ttb

spacing
none relative fraction
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

Spacing to insert between items where no explicit spacing was provided.

默认:none

children
relative fraction content
必需参数位置参数
位置参数按顺序传入,不带名称。
可变参数
可变参数可以多次传入。

The children to stack along the axis.