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

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

A table of contents, figures, or other elements.

This function generates a list of all occurrences of an element in the document, up to a given depth. The element's numbering and page number will be displayed in the outline alongside its title or caption. By default this generates a table of contents.

Example

#outline()

= Introduction
#lorem(5)

= Prior work
#lorem(10)
Preview

Alternative outlines

By setting the target parameter, the outline can be used to generate a list of other kinds of elements than headings. In the example below, we list all figures containing images by setting target to figure.where(kind: image). We could have also set it to just figure, but then the list would also include figures containing tables or other material. For more details on the where selector, see here.

#outline(
  title: [List of Figures],
  target: figure.where(kind: image),
)

#figure(
  image("tiger.jpg"),
  caption: [A nice figure!],
)
Preview

Styling the outline

The outline element has several options for customization, such as its title and indent parameters. If desired, however, it is possible to have more control over the outline's look and style through the outline.entry element.

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

title
none auto content
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

The title of the outline.

The outline's heading will not be numbered by default, but you can force it to be with a show-set rule: show outline: set heading(numbering: "1.")

默认:auto

查看示例

  

target
label selector function
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

The type of element to include in the outline.

To list figures containing a specific kind of element, like a table, you can write figure.where(kind: table).

默认:heading.where(outlined: true)

查看示例
#outline(
  title: [List of Tables],
  target: figure.where(kind: table),
)

#figure(
  table(
    columns: 4,
    [t], [1], [2], [3],
    [y], [0.3], [0.7], [0.5],
  ),
  caption: [Experiment results],
)
Preview

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

The maximum level up to which elements are included in the outline. When this argument is none, all elements are included.

默认:none

查看示例
#set heading(numbering: "1.")
#outline(depth: 2)

= Yes
Top-level section.

== Still
Subsection.

=== Nope
Not included.
Preview

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

How to indent the outline's entries.

Migration hints: Specifying true (equivalent to auto) or false (equivalent to none) for this option is deprecated and will be removed in a future release.

默认:none

查看示例
#set heading(numbering: "1.a.")

#outline(
  title: [Contents (Automatic)],
  indent: auto,
)

#outline(
  title: [Contents (Length)],
  indent: 2em,
)

#outline(
  title: [Contents (Function)],
  indent: n => [] * n,
)

= About ACME Corp.
== History
=== Origins
#lorem(10)

== Products
#lorem(10)
Preview

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

Content to fill the space between the title and the page number. Can be set to none to disable filling.

默认:repeat(body: [.])

查看示例
#outline(fill: line(length: 100%))

= A New Beginning
Preview

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

entry

Represents each entry line in an outline, including the reference to the outlined element, its page number, and the filler content between both.

This element is intended for use with show rules to control the appearance of outlines. To customize an entry's line, you can build it from scratch by accessing the level, element, body, fill and page fields on the entry.

outline.entry() -> content
查看示例
#set heading(numbering: "1.")

#show outline.entry.where(
  level: 1
): it => {
  v(12pt, weak: true)
  strong(it)
}

#outline(indent: auto)

= Introduction
= Background
== History
== State of the Art
= Analysis
== Setup
Preview

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

The nesting level of this outline entry. Starts at 1 for top-level entries.

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

The element this entry refers to. Its location will be available through the location method on content and can be linked to.

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

The content which is displayed in place of the referred element at its entry in the outline. For a heading, this would be its number followed by the heading's title, for example.

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

The content used to fill the space between the element's outline and its page number, as defined by the outline element this entry is located in. When none, empty space is inserted in that gap instead.

Note that, when using show rules to override outline entries, it is recommended to wrap the filling content in a box with fractional width. For example, box(width: 1fr, repeat[-]) would show precisely as many - characters as necessary to fill a particular gap.

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

The page number of the element this entry links to, formatted with the numbering set for the referenced page.