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

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

An inline-level container that sizes content.

All elements except inline math, text, and boxes are block-level and cannot occur inside of a paragraph. The box function can be used to integrate such elements into a paragraph. Boxes take the size of their contents by default but can also be sized explicitly.

Example

Refer to the docs
#box(
  height: 9pt,
  image("docs.svg")
)
for more information.
Preview

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

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

The width of the box.

Boxes can have fractional widths, as the example below demonstrates.

Note: Currently, only boxes and only their widths might be fractionally sized within paragraphs. Support for fractionally sized images, shapes, and more might be added in the future.

默认值:

auto

展开例子
Line in #box(width: 1fr, line(length: 100%)) between.
Preview

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

The height of the box.

默认值:

auto

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

An amount to shift the box's baseline by.

默认值:

0pt

展开例子
Image: #box(baseline: 40%, image("tiger.jpg", width: 2cm)).
Preview

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

The box's background color. See the rectangle's documentation for more details.

默认值:

none

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

The box's border color. See the rectangle's documentation for more details.

默认值:

none

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

How much to round the box's corners. See the rectangle's documentation for more details.

默认值:

0pt

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

How much to pad the box's content.

Note: When the box contains text, its exact size depends on the current text edges.

默认值:

0pt

展开例子
#rect(inset: 0pt)[Tight]
Preview

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

How much to expand the box's size without affecting the layout.

This is useful to prevent padding from affecting line layout. For a generalized version of the example below, see the documentation for the raw text's block parameter.

默认值:

0pt

展开例子
An inline
#box(
  fill: luma(235),
  inset: (x: 3pt, y: 0pt),
  outset: (y: 3pt),
  radius: 2pt,
)[rectangle].
Preview

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

Whether to clip the content inside the box.

默认值:

false

body
位置参数
位置参数
位置参数按顺序传入,不带参数名。
可用set规则
可用set规则
可用set规则设置参数,更改后续调用时的默认值。

The contents of the box.

默认值:

none

转到官方文档(英文)

搜索