# Captions for Tables and Figures

In **Telerik’s RadRichTextBox** you can easily insert images, tables, etc. Now it is possible to label these by inserting **captions**. This will help you define an image or a table and then refer to it later.

## Insert Caption

You can open the **Caption** window by clicking on the **Caption** button.

![Rad Rich Text Box Features Captions For Tables And Figures 01](https://www.telerik.com/products/wpf/documentation/assets/3fa6d4daa7206ccb4ff69c6815da502b/radrichtextbox_features_captions_for_tables_and_figures_01.png)

If the caret is inside a table, the caret would look like this:

![Rad Rich Text Box Features Captions For Tables And Figures 02](https://www.telerik.com/products/wpf/documentation/assets/0f9fda4b917057bd0c6b1bb2856c213b/radrichtextbox_features_captions_for_tables_and_figures_02.png)

### Caption Preview

On the top there is a preview of the caption text that would be inserted. In this case we haven’t inserted any other captions with label “Table” so the number that follows is 1. That number represents the number of captions inserted before that one with the same label.

### Options

You can select different options. The first one is **Label**. From here you can select the label text. By default you have two options – **Figure** and **Table**.

![Rad Rich Text Box Features Captions For Tables And Figures 03](https://www.telerik.com/products/wpf/documentation/assets/e9e9d95a61ec3534cc1688dabeca220b/radrichtextbox_features_captions_for_tables_and_figures_03.png)

You can also specify the **Position** of the caption - **Above selected item** or **Below selected item**

We will have this option only if the caret is in a table or on an image. Otherwise it will be disabled.

### Creating and deleting labels

You can add new labels by using the **New Label…** dialog and of course delete old ones with the **Delete Label** button.

![Rad Rich Text Box Features Captions For Tables And Figures 04](https://www.telerik.com/products/wpf/documentation/assets/5ddbb1974bb3109d1c014b298c7e95a3/radrichtextbox_features_captions_for_tables_and_figures_04.png)

> You cannot delete the two default labels - **Figure** and **Table**

When **Exclude label from caption** checkbox is checked the label text will be removed and only the number will be left.

### Format

You can control how the numbering is displayed by using the **Format** ComboBox. You can see the available formats in the picture below. By default the (“1, 2, 3, …”) format is selected.

![Rad Rich Text Box Features Captions For Tables And Figures 05](https://www.telerik.com/products/wpf/documentation/assets/29c3cca1143fdc0da72527ceceaa97af/radrichtextbox_features_captions_for_tables_and_figures_05.png)

### Include chapter number

When the **Include chapter number** checkbox is checked, every time you insert a **Caption** in a new section, the numbering is restarted. That’s why the preview now looks like this:

![Rad Rich Text Box Features Captions For Tables And Figures 06](https://www.telerik.com/products/wpf/documentation/assets/dd75d917e6497ef812ff0cd17ac3a7a0/radrichtextbox_features_captions_for_tables_and_figures_06.png)

The first number shows the bullet of the section you are currently in, and the second number shows the number of **Captions** being inserted in this section.

A section is defined by the **Heading** styles, but only when they are in a list. You can choose which **Heading** style the chapter starts from and what separator to use. There are several available separators – **hyphen**, **period**, **colon**.

![Rad Rich Text Box Features Captions For Tables And Figures 07](https://www.telerik.com/products/wpf/documentation/assets/217ea15bdd6136c3505ed3aead0ee71a/radrichtextbox_features_captions_for_tables_and_figures_07.png)

### Insert

Clicking on the **OK** button will insert the **Caption**.It would look like this:

![Rad Rich Text Box Features Captions For Tables And Figures 08](https://www.telerik.com/products/wpf/documentation/assets/8cfe12ed7a01f97cfe2b477af6af6830/radrichtextbox_features_captions_for_tables_and_figures_08.png)

Here the **Below selected item** position is chosen, **:** for separator and **A, B, C…** for formatting.

## Inserting a Caption using RadRichTextBox's API

Using Telerik’s rich text editor’s API is pretty straight forward. There is a method called **InsertCaption()** on **RadRichTextBox** which you can use to insert a new **Caption** into the document with a custom label. The method has the following signature:

```C#
public void InsertCaption(CaptionDefinition definition, string caption, bool includeLabel, bool insertBelow)
```

The **CaptionDefinition** class contains viable information for the creation of the caption like **Label**, **NumberingFormat** and **SeparatorType**. The “caption” parameter is of type string and represents the text in the caption that will be inserted after the number (also known as caption text). The “includeLabel” parameter is of type Boolean and if true will include the label text to the caption. The “insertBelow” parameter is of type Boolean as well and if true will insert the caption below the table or figure. So, in order to insert a caption using this method you would do something like:

```C#
    CaptionDefinition captionDefinition = new CaptionDefinition();
captionDefinition.Label = "testLabel";
	captionDefinition.NumberingFormat = Documents.Model.Fields.NumberingFormat.Arabic;
	captionDefinition.SeparatorType = Documents.Model.Fields.CaptionSeparatorType.Colon;
	this.radRichTextBox1.InsertCaption(captionDefinition, "captionText", true, true);
```

The **RadDocument** contains the two default **CaptionDefinitions** by default. They reside in a collection called “CaptionDefinitions” which is of type Dictionary\<string, CaptionDefinition>. If you want to insert a caption of a default type, you can do as follow:

```C#
	this.radRichTextBox1.InsertCaption(this.editor.Document.CaptionDefinitions["Table"], "captionText", true, true);
```

This code will insert a default caption with label **Table**.
