ArcGIS text formatting tags let you modify the formatting for a portion of text. This lets you create mixed-format text where, for example, one word in a sentence is underlined. Text formatting tags can be used almost anywhere text is placed on or around the map in ArcMap. You can use the tags anywhere you can specify both a text string and a text symbol. For example, you can use tags in dynamic label expressions, annotation, legend text, map titles, and in the values of fields used to label features. Tags aren't resolved by the ArcMap table of contents, Table window, or Identify Results window, so tags added to field values will be visible as tags in those windows.
Dynamic text is another type of formatting tag, which changes graphic text dynamically based on the current value of its respective property. It is only available in layout view. Dynamic text tags can be used together with text formatting tags to create dynamic mixed-format text on the page layout.
Formatting tag syntax
Formatting tags have different syntax depending on whether they are used in annotation or in a label expression. In annotation the tags are concatenated to the text string with no special characters:
While in label expressions the formatting tags must be surrounded by double quotes and concatenated to other parts of the expression using the & operator:
"<BOL>" & "Text" & "</BOL>" "<BOL>" & [LABELFIELD] & "</BOL>"
The following syntax rules apply to formatting tags in ArcMap:
- The ArcGIS text formatting tags adhere to XML syntax rules. Each start tag must be accompanied by an end tag. Tags can be nested, but you must close the inner tag before closing an outer tag:
"<BOL><UND>" & [LABELFIELD] & "</UND></BOL>"
- Tag attributes may be surrounded by either single or double quotes. The following statements are equivalent:
<FNT name='Arial' size='18'>My text</FNT> <FNT name="Arial" size="18">My text</FNT>
"<FNT name=""Arial"" size=""18"">" & [LABELFIELD] & "</FNT>" "<FNT name='Arial' size='18'>" & [LABELFIELD] & "</FNT>"
- The case of tag pairs must match exactly. Therefore, <BOL>...</BOL> is valid, as is <bol>...</bol>, but <Bol>...</bol> is invalid.
- Any unrecognized, balanced tag pairs will be ignored by the parser. For example, even though <notag> is not a valid ArcGIS formatting tag, the following string is valid and will be displayed properly:
"<notag><BOL>" & "State College" & "<BOL></notag>"
- The ampersand (&) and angle bracket (<) are special characters and are not valid in your text if formatting tags are used. Use the equivalent character codes & and < instead.
Instead of <ITA>John & Paul</ITA>, use:
<ITA>John & Paul</ITA>
This expression displays the values of the label field inside < > characters:
"<ITA><" & [LABELFIELD] & "></ITA>"
If you have special characters embedded in the values of the label field, you can replace them dynamically using a simple label script:
Function FindLabel ([LABELFIELD]) NewString = Replace([LABELFIELD],"&","&") FindLabel = "<ITA>" & NewString & "</ITA>" End Function
- Every piece of text on a map has a symbol that is used when it is drawn. Formatting tags work by temporarily modifying this base text symbol and drawing the specified portion of the text with the formatting specified in the tag. The buttons and commands on the Draw toolbar and in the Symbol Selector always reflect the properties of the base text symbol for the selected piece of text and do not reflect modifications made using formatting tags. For example, if you use the <FNT> tag to change the font of a piece of text, the Font menu on the Draw toolbar will not reflect this change when this text is selected on the map; it will show you the font of the text's base symbol.
- Tags have no effect on a piece of text if they simply repeat an existing property of the base text symbol. Generally, this behavior is intuitive; for example, if you have a <BOL> tag in your text string but the base text symbol is already bold, the <BOL> tag in your string will have no effect. Also, because tags follow the rules of XML, it would be illegal to try and use a </BOL> tag to turn off the bold property of a base text symbol. Instead, you can use the <_BOL> tag for this purpose.
This is bold if the base text symbol is bold <_BOL>, but this is not: </_BOL>
"This is bold if the base text symbol is bold<_BOL>, but this is not: </_BOL>"
Additional tips for building label expressions
The following tips will help you build your label expressions:
- To check the validity of expressions containing text formatting tags, click the Verify button or Apply your changes and view the labels on the map. In the case of invalid formatting tags or syntax, tags appear as plain text in the Verify window and map labels.
- Tags are not interpreted by Python/VBScript/JScript. Instead, they are passed to the ArcMap framework as plain text to be dynamically formatted as they are drawn. You don't need to quote tags included inside quoted strings:
"Current <BOL>status</BOL> of parcel: " & [LABELFIELD]
- Formatting tags can be embedded in the values of the field you use to label a layer's features whether or not you use a label expression. In this way, you can change the format of any portion of a particular value in a label field. To embed formatting tags, the label field must be of string type. Tags and tag attributes used in field values do not need to be surrounded by quotes, so the following are valid values for a label field:
<ITA>Rochester</ITA> <FNT size='14'>C</FNT>olorado