提示:本教程存在过时问题,更详细教程请阅读 小蓝书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 中文文档

length

A size or distance, possibly expressed with contextual units.

Typst supports the following length units:

You can multiply lengths with and divide them by integers and floats.

Example

#rect(width: 20pt)
#rect(width: 2em)
#rect(width: 1in)

#(3em + 5pt).em \
#(20pt).em \
#(40em + 2pt).abs \
#(5em).abs
Preview

Fields

定义
函数和类型可以有与其关联的定义 (成员或方法)。可以使用 "." 操作符来访问调用它们。

pt

Converts this length to points.

Fails with an error if this length has non-zero em units (such as 5em + 2pt instead of just 2pt). Use the abs field (such as in (5em + 2pt).abs.pt()) to ignore the em component of the length (thus converting only its absolute component).

self.pt(
) -> float

mm

Converts this length to millimeters.

Fails with an error if this length has non-zero em units. See the pt method for more details.

self.mm(
) -> float

cm

Converts this length to centimeters.

Fails with an error if this length has non-zero em units. See the pt method for more details.

self.cm(
) -> float

inches

Converts this length to inches.

Fails with an error if this length has non-zero em units. See the pt method for more details.

self.inches(
) -> float