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

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

A raster or vector graphic.

Supported formats are PNG, JPEG, GIF and SVG.

Note: Work on SVG export is ongoing and there might be visual inaccuracies in the resulting PDF. Make sure to double-check embedded SVG images. If you have an issue, also feel free to report it on GitHub.

Example

#figure(
  image("molecular.jpg", width: 80%),
  caption: [
    A step in the molecular testing
    pipeline of our lab.
  ],
)
Preview

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

path
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

Path to an image file.

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

The image's format. Detected automatically by default.

默认值:

auto

可填写的值
  • png

    Raster format for illustrations and transparent graphics.

  • jpg

    Lossy raster format suitable for photos.

  • gif

    Raster format that is typically used for short animated clips.

  • svg

    The vector graphics format of the web.

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

The width of the image.

默认值:

auto

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

The height of the image.

默认值:

auto

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

A text describing the image.

默认值:

none

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

How the image should adjust itself to a given area.

默认值:

"cover"

可填写的值
  • cover

    The image should completely cover the area. This is the default.

  • contain

    The image should be fully contained in the area.

  • stretch

    The image should be stretched so that it exactly fills the area, even if this means that the image will be distorted.

定义
定义
这些函数和类型带有附属定义。要访问这种定义,请先写上函数或类型的名称,再加上定义的名称,并用句点在中间分隔。

decode

Decode a raster or vector graphic from bytes or a string.

展开例子
#let original = read("diagram.svg")
#let changed = original.replace(
  "#2B80FF", // blue
  green.to-hex(),
)

#image.decode(original)
#image.decode(changed)
Preview

data
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The data to decode as an image. Can be a string for SVGs.

format

The image's format. Detected automatically by default.

可填写的值
  • png

    Raster format for illustrations and transparent graphics.

  • jpg

    Lossy raster format suitable for photos.

  • gif

    Raster format that is typically used for short animated clips.

  • svg

    The vector graphics format of the web.

width

The width of the image.

height

The height of the image.

alt

A text describing the image.

fit

How the image should adjust itself to a given area.

可填写的值
  • cover

    The image should completely cover the area. This is the default.

  • contain

    The image should be fully contained in the area.

  • stretch

    The image should be stretched so that it exactly fills the area, even if this means that the image will be distorted.

转到官方文档(英文)

搜索