Table of Contents

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.

Shell
pnpm add @univerjs/docs-toc @univerjs/docs-toc-ui
TypeScript
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.

TypeScript
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.

How is this guide?

© 2026 DreamNum Co., Ltd.