Setting a label

Labels are textual information you can display on vector features. They add details you could not necessarily represent using symbols.

The Style Manager dialog allows you to create a set of labels or text formats (ie the appearance of the text, including font, size, colors, shadow, background…). Each of these items could later be applied to layers in the labeling Labels tab of the vector Layer Properties dialog or Layer Styling panel or using the labeling Layer Labeling Options button of the Labels toolbar. You can also directly configure them in the abovementioned dialogs.

The Label Settings dialog allows you to configure smart labeling for vector layers. Setting a label includes configuring the text format, and how the label relates with the features or other labels (through placement, rendering and callout).

Formatting the label text

To create text formats, you can:

  1. Open the styleManager Style Manager dialog

  2. Activate the Text format tab

    ../../../_images/stylemanager_textformat.png

    Text formats in Style Manager dialog

  3. Press the signPlus Add item button. The Text Settings dialog opens with the following properties.

Text tab

../../../_images/textsettings_text.png

Text settings - Text tab

In the text Text tab, you can set:

  • the Font, from the ones available on your machine
  • the Style: along with the common styles of the font, you can set whether the text should be underlined or striked through
  • the Size that can be in Points, Pixels, Millimeters, Map units, Meters at scale, or Inches
  • the Color
  • and the Opacity.

At the bottom, a text formats list widget shows a filterable list of text formats stored within your style manager database. This allows you to easily set text formats to match styles saved in the local style database, and also to add a new text format to the style database based on the current settings. Press the Save format… button to store the current text format in the Style Manager, providing a name and tag(s).

Likewise, a label settings list widget is shown when configuring labels, allowing you to pick from the styleManager Style Manager widget or to add new styles to it.

Formatting tab

../../../_images/textsettings_formatting.png

Text settings - Formatting tab

In the labelformatting Formatting tab, you can:

  • Use the Type case option to change the capitalization style of the text. You have the possibility to render the text as All uppercase, All lowercase or Capitalize first letter. Note that the last option modifies only the first letter of each word and leaves the other letters in the text untouched.

  • Under Spacing, change the space between words and between individual letters.

  • checkbox Enable kerning of the text font

  • Set the Text orientation which can be Horizontal or Vertical. It can also be Rotation-based when setting a label.

  • Use the Blend mode option to determine how your labels will mix with the map features below them (more details at Blending Modes).

  • The unchecked Apply label text substitutes option allows you to specify a list of texts to substitute to texts in feature labels (e.g., abbreviating street types). Replacement texts are used when displaying labels on the map. Users can also export and import lists of substitutes to make reuse and sharing easier.

  • Configure Multiple lines:

    • Set a character that will force a line break in the text with the Wrap on character option

    • Set an ideal line size for auto-wrapping using the Wrap lines to option. The size can represent either the Maximum line length or the Minimum line length.

    • Decide the Line Height

    • Format the Alignment: typical values available are Left, Right and Center.

      When setting point labels properties, the text alignment can also be Follow label placement. In that case, the alignment will depend on the final placement of the label relative to the point. E.g., if the label is placed to the left of the point, then the label will be right aligned, while if it is placed to the right, it will be left aligned.

  • For line labels you can include Line direction symbol to help determine the line directions, with symbols to use to indicate the Left or Right. They work particularly well when used with the curved or Parallel placement options from the Placement tab. There are options to set the symbols position, and to unchecked Reverse direction.

  • Use the unchecked Formatted numbers option to format numeric texts. You can set the number of Decimal places. By default, 3 decimal places will be used. Use the checkbox Show plus sign if you want to show the plus sign for positive numbers.

Buffer tab

../../../_images/textsettings_buffer.png

Text settings - Buffer tab

To create a buffer around the label, activate the checkbox Draw text buffer checkbox in the labelbuffer Buffer tab. Then you can:

  • Set the buffer’s Size that can be in Points, Pixels, Millimeters, Map units, Meters at scale or Inches
  • Select the buffer’s Color
  • checkbox Color buffer’s fill: The buffer expands from the label’s outline, so, if the option is activated, the label’s interior is filled. This may be relevant when using partially transparent labels or with non-normal blending modes, which will allow seeing behind the label’s text. Unchecking the option (while using totally transparent labels) will allow you to create outlined text labels.
  • Define the buffer’s Opacity
  • Apply a Pen join style: it can be Round, Miter or Bevel
  • Use the Blend mode option to determine how your label’s buffer will mix with the map components below them (more details at Blending Modes).
  • Check unchecked Draw effects to add advanced paint effects for customizing the visualization of the labels.

Background tab

In the labelbackground Background tab, you can define with Size X and Size Y the shape of your background. Use Size type to insert an additional ‘Buffer’ into your background. The buffer size is set by default here. The background then consists of the buffer plus the background in Size X and Size Y. You can set a Rotation where you can choose between ‘Sync with label’, ‘Offset of label’ and ‘Fixed’. Using ‘Offset of label’ and ‘Fixed’, you can rotate the background. Define an Offset X,Y with X and Y values, and the background will be shifted. When applying Radius X,Y, the background gets rounded corners. Again, it is possible to mix the background with the underlying layers in the map canvas using the Blend mode (see Blending Modes).

Shadow tab

Use the labelshadow Shadow tab for a user-defined Draw drop shadow. The drawing of the background is very variable. Choose between ‘Lowest label component’, ‘Text’, ‘Buffer’ and ‘Background’. The Offset angle depends on the orientation of the label. If you choose the checkbox Use global shadow checkbox, then the zero point of the angle is always oriented to the north and doesn’t depend on the orientation of the label. You can influence the appearance of the shadow with the Blur radius. The higher the number, the softer the shadows. The appearance of the drop shadow can also be altered by choosing a blend mode.

Placement tab

Choose the labelplacement Placement tab for configuring label placement and labeling priority. Note that the placement options differ according to the type of vector layer, namely point, line or polygon, and are affected by the global PAL setting.

Placement for point layers

With the radioButtonOn Cartographic placement mode, point labels are generated with a better visual relationship with the point feature, following ideal cartographic placement rules. Labels can be placed at a set Distance either from the point feature itself or from the bounds of the symbol used to represent the feature. The latter option is especially useful when the symbol size isn’t fixed, e.g. if it’s set by a data defined size or when using different symbols in a categorized renderer.

By default, placements are prioritised in the following order:

  1. top right
  2. top left
  3. bottom right
  4. bottom left
  5. middle right
  6. middle left
  7. top, slightly right
  8. bottom, slightly left.

Placement priority can, however, be customized or set for an individual feature using a data defined list of prioritised positions. This also allows only certain placements to be used, so e.g. for coastal features you can prevent labels being placed over the land.

The radioButtonOn Around point setting places the label in an equal radius (set in Distance) circle around the feature. The placement of the label can even be constrained using the Quadrant option.

With the radioButtonOn Offset from point, labels are placed at a fixed offset from the point feature. You can select the Quadrant in which to place your label. You are also able to set the Offset X,Y distances between the points and their labels and can alter the angle of the label placement with the Rotation setting. Thus, placement in a selected quadrant with a defined rotation is possible.

Placement for line layers

Label options for line layers include radioButtonOn Parallel, radioButtonOff Curved or radioButtonOff Horizontal. For the radioButtonOn Parallel and radioButtonOff Curved options, you can set the position to checkbox Above line, checkbox On line and checkbox Below line. It’s possible to select several options at once. In that case, QGIS will look for the optimal label position. For Parallel and curved placement options, you can also use the line orientation for the position of the label. Additionally, you can define a Maximum angle between curved characters when selecting the radioButtonOff Curved option (see Figure_labels_placement_line).

../../../_images/line_label_placement.png

Label placement examples in lines

For all three placement options, in Repeat, you can set up a minimum distance for repeating labels. The distance can be in mm or in map units.

Placement for polygon layers

You can choose one of the following options for placing labels in polygons (see figure_labels_placement_polygon):

  • radioButtonOn Offset from centroid,
  • radioButtonOff Horizontal (slow),
  • radioButtonOff Around centroid,
  • radioButtonOff Free (slow),
  • radioButtonOff Using perimeter,
  • and radioButtonOff Using perimeter (curved).

In the Offset from centroid settings you can specify if the centroid is of the radioButtonOn visible polygon or radioButtonOff whole polygon. That means that either the centroid is used for the polygon you can see on the map or the centroid is determined for the whole polygon, no matter if you can see the whole feature on the map. You can place your label within a specific quadrant, and define offset and rotation.

The Around centroid setting places the label at a specified distance around the centroid. Again, you can define radioButtonOn visible polygon or radioButtonOff whole polygon for the centroid.

With the Horizontal (slow) or Free (slow) options, QGIS places at the best position either a horizontal or a rotated label inside the polygon.

With the Using perimeter option, the label will be drawn next to the polygon boundary. The label will behave like the parallel option for lines. You can define a position and a distance for the label. For the position, checkbox Above line, checkbox On line, checkbox Below line and checkbox Line orientation dependent position are possible. You can specify the distance between the label and the polygon outline, as well as the repeat interval for the label.

The Using perimeter (curved) option helps you draw the label along the polygon boundary, using a curved labeling. In addition to the parameters available with Using perimeter setting, you can set the Maximum angle between curved characters polygon, either inside or outside.

../../../_images/polygon_label_placement.png

Label placement examples in polygons

In the priority section you can define the priority with which labels are rendered for all three vector layer types (point, line, polygon). This placement option interacts with the labels from other vector layers in the map canvas. If there are labels from different layers in the same location, the label with the higher priority will be displayed and the others will be left out.

Rendering tab

In the render Rendering tab, you can tune when the labels can be rendered and their interaction with other labels and features.

Under Label options, you find the scale-based and the Pixel size-based visibility settings.

The Label z-index determines the order in which labels are rendered, as well in relation with other feature labels in the layer (using data-defined override expression), as with labels from other layers. Labels with a higher z-index are rendered on top of labels (from any layer) with lower z-index.

Additionally, the logic has been tweaked so that if 2 labels have matching z-indexes, then:

  • if they are from the same layer, the smaller label will be drawn above the larger label
  • if they are from different layers, the labels will be drawn in the same order as their layers themselves (ie respecting the order set in the map legend).

Note that this setting doesn’t make labels to be drawn below the features from other layers, it just controls the order in which labels are drawn on top of all the layer’s features.

While rendering labels and in order to display readable labels, QGIS automatically evaluates the position of the labels and can hide some of them in case of collision. You can however choose to checkbox Show all labels for this layer (including colliding labels) in order to manually fix their placement.

With data-defined expressions in Show label and Always Show you can fine tune which labels should be rendered.

Under Feature options, you can choose to label every part of a multi-part feature and limit the number of features to be labeled. Both line and polygon layers offer the option to set a minimum size for the features to be labeled, using Suppress labeling of features smaller than. For polygon features, you can also filter the labels to show according to whether they completely fit within the feature or not. For line features, you can choose to Merge connected lines to avoid duplicate labels, rendering a quite airy map in conjunction with the Distance or Repeat options in Placement tab.

From the Obstacles frame, you can manage the covering relation between labels and features. Activate the checkbox Discourage labels from covering features option to decide whether features of the layer should act as obstacles for any label (including labels from other features in the same layer). An obstacle is a feature QGIS tries as far as possible to not place labels over. Instead of the whole layer, you can define a subset of features to use as obstacles, using the dataDefined data-defined override control next to the option.

The slider priority control slider for obstacles allows you to make labels prefer to overlap features from certain layers rather than others. A Low weight obstacle priority means that features of the layer are less considered as obstacles and thus more likely to be covered by labels. This priority can also be data-defined, so that within the same layer, certain features are more likely to be covered than others.

For polygon layers, you can choose the type of obstacle features could be by minimising the labels placement:

  • over the feature’s interior: avoids placing labels over the interior of the polygon (prefers placing labels totally outside or just slightly inside the polygon)
  • or over the feature’s boundary: avoids placing labels over boundary of the polygon (prefers placing labels outside or completely inside the polygon). E.g., it can be useful for regional boundary layers, where the features cover an entire area. In this case, it’s impossible to avoid placing labels within these features, and it looks much better to avoid placing them over the boundaries between features.