# Table of Contents

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

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

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.0.0`

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

---

A table of contents inserts heading entries into the document body. It is separate from the outline navigation panel. Add these plugins to your Docs core setup before creating a document, merge the UI locale into `locales`, and load the stylesheet. Neither the Docs core nor the Docs advanced preset includes them.

#### 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/en-US'
import { LocaleType } from '@univerjs/core'

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

univerAPI.loadLocales(LocaleType.EN_US, FeatureLocale)

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

## Insert and update

Place the cursor in the document before insertion. The UI supports insertion, full updates, page-number-only updates, and deletion. When no `rangeId` is passed, updates target the TOC at the current selection.

```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' })
```

The updater evaluates outline-level TOC instructions (`\o`). Other imported Word switches are retained in FIELD metadata but are not all evaluated. See the [command parameters](https://docs.univer.ai/reference/packages/plugins/univerjs/docs-toc.md).
