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

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

Layouts its child onto one or multiple pages.

Although this function is primarily used in set rules to affect page properties, it can also be used to explicitly render its argument onto a set of pages of its own.

Pages can be set to use auto as their width or height. In this case, the pages will grow to fit their content on the respective axis.

The Guide for Page Setup explains how to use this and related functions to set up a document with many examples.

Example

#set page("us-letter")

There you go, US friends!
Preview

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

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

A standard paper size to set width and height.

默认:"a4"

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

The width of the page.

默认:595.28pt

查看示例
#set page(
  width: 3cm,
  margin: (x: 0cm),
)

#for i in range(3) {
  box(square(width: 1cm))
}
Preview

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

The height of the page.

If this is set to auto, page breaks can only be triggered manually by inserting a page break. Most examples throughout this documentation use auto for the height of the page to dynamically grow and shrink to fit their content.

默认:841.89pt

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

Whether the page is flipped into landscape orientation.

默认:false

查看示例
#set page(
  "us-business-card",
  flipped: true,
  fill: rgb("f2e5dd"),
)

#set align(bottom + end)
#text(14pt)[*Sam H. Richards*] \
_Procurement Manager_

#set text(10pt)
17 Main Street \
New York, NY 10001 \
+1 555 555 5555
Preview

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

The page's margins.

The values for left and right are mutually exclusive with the values for inside and outside.

默认:(:)

查看示例
#set page(
 width: 3cm,
 height: 4cm,
 margin: (x: 8pt, y: 4pt),
)

#rect(
  width: 100%,
  height: 100%,
  fill: aqua,
)
Preview

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

On which side the pages will be bound.

This affects the meaning of the inside and outside options for margins.

默认:auto

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

How many columns the page has.

If you need to insert columns into a page or other container, you can also use the columns function.

默认:1

查看示例
#set page(columns: 2, height: 4.8cm)
Climate change is one of the most
pressing issues of our time, with
the potential to devastate
communities, ecosystems, and
economies around the world. It's
clear that we need to take urgent
action to reduce our carbon
emissions and mitigate the impacts
of a rapidly changing climate.
Preview

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

The page's background color.

This instructs the printer to color the complete page with the given color. If you are considering larger production runs, it may be more environmentally friendly and cost-effective to source pre-dyed pages and not set this property.

默认:none

查看示例
#set page(fill: rgb("444352"))
#set text(fill: rgb("fdfdfd"))
*Dark mode enabled.*
Preview

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

How to number the pages.

If an explicit footer (or header for top-aligned numbering) is given, the numbering is ignored.

默认:none

查看示例
#set page(
  height: 100pt,
  margin: (top: 16pt, bottom: 24pt),
  numbering: "1 / 1",
)

#lorem(48)
Preview

number-align
alignment
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

The alignment of the page numbering.

If the vertical component is top, the numbering is placed into the header and if it is bottom, it is placed in the footer. Horizon alignment is forbidden. If an explicit matching header or footer is given, the numbering is ignored.

默认:center + bottom

查看示例
#set page(
  margin: (top: 16pt, bottom: 24pt),
  numbering: "1",
  number-align: right,
)

#lorem(30)
Preview

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

The page's header. Fills the top margin of each page.

默认:none

查看示例
#set par(justify: true)
#set page(
  margin: (top: 32pt, bottom: 20pt),
  header: [
    #set text(8pt)
    #smallcaps[Typst Academcy]
    #h(1fr) _Exercise Sheet 3_
  ],
)

#lorem(19)
Preview

header-ascent
relative
可用 Set 规则
可以使用 Set 规则,为函数后续所有的使用设置默认参数。

The amount the header is raised into the top margin.

默认:30%

The page's footer. Fills the bottom margin of each page.

For just a page number, the numbering property, typically suffices. If you want to create a custom footer, but still display the page number, you can directly access the page counter.

默认:none

查看示例
#set par(justify: true)
#set page(
  height: 100pt,
  margin: 20pt,
  footer: [
    #set align(right)
    #set text(8pt)
    #counter(page).display(
      "1 of I",
      both: true,
    )
  ]
)

#lorem(48)
Preview

The amount the footer is lowered into the bottom margin.

默认:30%

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

Content in the page's background.

This content will be placed behind the page's body. It can be used to place a background image or a watermark.

默认:none

查看示例
#set page(background: rotate(24deg,
  text(18pt, fill: rgb("FFCBC4"))[
    *CONFIDENTIAL*
  ]
))

= Typst's secret plans
In the year 2023, we plan to take
over the world (of typesetting).
Preview

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

Content in the page's foreground.

This content will overlay the page's body.

默认:none

查看示例
#set page(foreground: text(24pt)[🥸])

Reviewer 2 has marked our paper
"Weak Reject" because they did
not understand our approach...
Preview

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

The contents of the page(s).

Multiple pages will be created if the content does not fit on a single page. A new page with the page properties prior to the function invocation will be created after the body has been typeset.