# 目錄

- Human documentation: [https://docs.univer.ai/zh-TW/guides/docs/features/table-of-contents](https://docs.univer.ai/zh-TW/guides/docs/features/table-of-contents)

- Agent Markdown: [https://docs.univer.ai/zh-TW/guides/docs/features/table-of-contents.md](https://docs.univer.ai/zh-TW/guides/docs/features/table-of-contents.md)

- Requested language: `zh-TW`

- Content language: `zh-TW`

- Documentation version: `1.2.0`

- Source: [docs/features/table-of-contents.zh-TW.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/docs/features/table-of-contents.zh-TW.mdx)

---

目錄會在文件本文插入標題項目，與導覽用的大綱面板是不同功能。在 Docs 核心設定中，建立文件前加入以下外掛，將 UI 語言包合併至 `locales` 並載入樣式。Docs 核心與進階預設都未包含這兩個外掛。

#### npm

```bash
npm install @univerjs/docs-toc @univerjs/docs-toc-ui
```

#### pnpm

```bash
pnpm add @univerjs/docs-toc @univerjs/docs-toc-ui
```

#### yarn

```bash
yarn add @univerjs/docs-toc @univerjs/docs-toc-ui
```

#### bun

```bash
bun add @univerjs/docs-toc @univerjs/docs-toc-ui
```

```ts
import { UniverDocsTocPlugin } from '@univerjs/docs-toc'
import { UniverDocsTocUIPlugin } from '@univerjs/docs-toc-ui'
import FeatureLocale from '@univerjs/docs-toc-ui/locale/zh-TW'
import { LocaleType } from '@univerjs/core'

import '@univerjs/docs-toc-ui/lib/index.css'

univerAPI.loadLocales(LocaleType.ZH_TW, FeatureLocale)

univer.registerPlugin(UniverDocsTocPlugin)
univer.registerPlugin(UniverDocsTocUIPlugin)
```

## 插入與更新

插入前先將游標放入文件。UI 支援插入、更新整份目錄、僅更新頁碼與刪除。未傳入 `rangeId` 時，更新目前選取範圍所在的目錄。

```ts
import { InsertTableOfContentsCommand, UpdateTableOfContentsCommand } from '@univerjs/docs-toc'

await univerAPI.executeCommand(InsertTableOfContentsCommand.id, {
  levels: 3,
  showPageNumbers: true,
  rightAlignPageNumbers: true,
})
await univerAPI.executeCommand(UpdateTableOfContentsCommand.id, { mode: 'entireTable' })
```

更新器計算大綱層級目錄指令（`\o`）。其他匯入的 Word 開關會保留於 FIELD 中，但並非全部參與計算。完整參數見[命令參考](https://docs.univer.ai/zh-TW/reference/packages/plugins/univerjs/docs-toc.md)。
