How To: Stack labels from a single field using a Python expression
A feature can be labeled to contain descriptive text on the feature, by displaying the values in a certain field from the attribute table. In some cases, it is desirable to stack labels from a single field to reduce its horizontal length and to provide better a view, similar to the concept of word wrap. This is possible in ArcMap using the Label Manager in the Labeling toolbar with the Python expression.
The following steps describe how to stack labels from a single field:
- Enable the Labeling toolbar. Click Customize > Toolbars > Labeling.
- In the Labeling toolbar, click the Label Manager icon.
- Select the desired feature in the Label Classes segment.
- Click Expression.
- In the Label Expression window, check the Advanced box.
- In the Parser drop-down list, select the Python parser.
- In the Expression text box, type the following Python expression.
def FindLabel ([Field_Name]): x = [Field_Name] x1 = x.split(" ") if len(x1)>1: return x1 + '\n' + x1 else: return x1
Note: The array parameter x1[n] can be added and modified according to the number of words present in the value. For example: return x1 + '\n' + x1 + '\n' + x1
- Click OK.
- Click Apply on the Label Manager window, and click OK. The following images are sample of the before and after result.
- ArcGIS Desktop: Building label expressions
- ArcGIS Desktop: Essential labeling concepts
- ArcGIS Desktop: A quick tour of the Labeling toolbar
- ArcGIS Desktop: About stacking labels
- How To: Split labels from multiple fields to multiple lines in ArcMap
- How To: Create stacked labels from text in the same field