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

measure

Measures the layouted size of content.

The measure function lets you determine the layouted size of content. Note that an infinite space is assumed, therefore the measured height/width may not necessarily match the final height/width of the measured content. If you want to measure in the current layout dimensions, you can combine measure and layout.

Example

The same content can have a different size depending on the styles that are active when it is layouted. For example, in the example below #content is of course bigger when we increase the font size.

#let content = [Hello!]
#content
#set text(14pt)
#content
Preview

To do a meaningful measurement, you therefore first need to retrieve the active styles with the style function. You can then pass them to the measure function.

#let thing(body) = style(styles => {
  let size = measure(body, styles)
  [Width of "#body" is #size.width]
})

#thing[Hey] \
#thing[Welcome]
Preview

The measure function returns a dictionary with the entries width and height, both of type length.

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

measure() -> dictionary

content
content
必需参数位置参数
位置参数按顺序传入,不带名称。

The content whose size to measure.

styles
styles
必需参数位置参数
位置参数按顺序传入,不带名称。

The styles with which to layout the content.