# Styling Table of Contents with Multilevel List Numbering in Telerik WordsProcessing

## Environment

| Version    | Product            | Author                                                                |
| ---------- | ------------------ | --------------------------------------------------------------------- |
| 2025.3.806 | RadWordsProcessing | [Yoan Karamanov](https://www.telerik.com/blogs/author/yoan-karamanov) |

## Description

This article shows how to apply multilevel list numbering and other specific styles to each level of [Table Of Contents](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/fields/toc-field) (TOC) in a DOCX document, such as font size, indentations, and font weight.

This knowledge base article also answers the following questions:

* How to add multilevel list numbering to a TOC in Telerik WordsProcessing?
* How to customize TOC level styles programmatically?
* How to use `ParagraphProperties` and `CharacterProperties` to style a TOC?

## Solution

To achieve multilevel list numbering in your [Table Of Contents](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/fields/toc-field) (TOC) and apply custom styles to each level, follow these steps:

1. Set the [`NumberingFieldsProvider`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/fields/numbering-fields-provider) for the hierarchical numbering functionality.
2. Load your document using the [DocxFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/formats-and-conversion/word-file-formats/docx/docxformatprovider).
3. Add a table of contents field using the [RadFlowDocumentEditor](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor).
4. Configure hierarchical numbering by adding a list of type [`NumberedHierarchical`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists).
5. Style each TOC level by specifying its properties with [ParagraphProperties](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/style-properties#style-properties-in-styles) and [CharacterProperties](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/style-properties#style-properties-in-styles).

### Implementation

```csharp
using System;
using System.IO;
using System.Diagnostics;
using Telerik.Windows.Documents.Flow.Model;
using Telerik.Windows.Documents.Flow.FormatProviders.Docx;
using Telerik.Windows.Documents.Flow.Extensibility;

FlowExtensibilityManager.NumberingFieldsProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.NumberingFieldsProvider();

RadFlowDocument flowDocument;
DocxFormatProvider docxFormatProvider = new DocxFormatProvider();

// Load the document.
using (Stream input = File.OpenRead("input.docx"))
{
    flowDocument = docxFormatProvider.Import(input, null);
}

var editor = new RadFlowDocumentEditor(flowDocument);

// Insert table of contents field.
FieldInfo tocFieldInfo = editor.InsertField("TOC \f a");
tocFieldInfo.UpdateField();

// Create hierarchical numbering list for the TOC.
var tocList = flowDocument.Lists.Add(ListTemplateType.NumberedHierarchical);
tocList.MultilevelType = MultilevelType.Multilevel;

// Style TOC Level 1
var tocLevel1StyleId = BuiltInStyleNames.GetTocStyleIdByIndex(1);
flowDocument.StyleRepository.AddBuiltInStyle(tocLevel1StyleId);
var tocLevel1Style = flowDocument.StyleRepository.GetStyle(tocLevel1StyleId);
tocLevel1Style.CharacterProperties.FontSize.LocalValue = 13;
tocLevel1Style.ParagraphProperties.LeftIndent.LocalValue = 0;
tocLevel1Style.CharacterProperties.FontWeight.LocalValue = FontWeights.Bold;
tocLevel1Style.ParagraphProperties.HangingIndent.LocalValue = 35;
tocLevel1Style.ParagraphProperties.ListLevel.LocalValue = 0;
tocLevel1Style.ParagraphProperties.ListId.LocalValue = tocList.Id;

// Style TOC Level 2
var tocLevel2StyleId = BuiltInStyleNames.GetTocStyleIdByIndex(2);
flowDocument.StyleRepository.AddBuiltInStyle(tocLevel2StyleId);
var tocLevel2Style = flowDocument.StyleRepository.GetStyle(tocLevel2StyleId);
tocLevel2Style.ParagraphProperties.ListLevel.LocalValue = 1;
tocLevel2Style.ParagraphProperties.LeftIndent.LocalValue = 35;
tocLevel2Style.ParagraphProperties.HangingIndent.LocalValue = 35;
tocLevel2Style.CharacterProperties.FontSize.LocalValue = 13;
tocLevel2Style.ParagraphProperties.ListId.LocalValue = tocList.Id;

// Style TOC Level 3
var tocLevel3StyleId = BuiltInStyleNames.GetTocStyleIdByIndex(3);
flowDocument.StyleRepository.AddBuiltInStyle(tocLevel3StyleId);
var tocLevel3Style = flowDocument.StyleRepository.GetStyle(tocLevel3StyleId);
tocLevel3Style.ParagraphProperties.ListLevel.LocalValue = 2;
tocLevel3Style.ParagraphProperties.LeftIndent.LocalValue = 65;
tocLevel3Style.ParagraphProperties.HangingIndent.LocalValue = 35;
tocLevel3Style.CharacterProperties.FontSize.LocalValue = 13;
tocLevel3Style.ParagraphProperties.ListId.LocalValue = tocList.Id;

// Export the styled document
string docxOutputPath = "..\\..\\..\\output.docx";
File.Delete(docxOutputPath);
using (Stream output = File.OpenWrite(docxOutputPath))
{
    docxFormatProvider.Export(flowDocument, output, null);
}
```

## See Also

* [WordsProcessing Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/overview)
* [Table of Contents Field](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/fields/toc-field)
* [ParagraphProperties API Reference](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/style-properties#style-properties-in-styles)
* [CharacterProperties API Reference](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/style-properties#style-properties-in-styles)
