Multi-line Labels in QGIS

Ever wondered how to create multi-line labels in QGIS? The new labeling engine has a “Multiline labels” option but it’s not so obvious how to create a usable labeling attribute. Here is how it works (credits to @nhopton on QGIS forum):

  1. Create a big enough text field (if the data doesn’t contain any yet).
  2. In Layer Properties – Fields, chose a “Text edit” edit widget for the label field.
  3. Enter the multi-line text into the label field. You can do this using Attribute Table or Feature Form.

    A feature form with "Text edit" widget

  4. Activate labeling. You’ll have to tick “Multiline labels” option in Layer Labeling Settings – Advanced – Options. That’s it:

    Simple multi-line label example

A common use case is the wish to show multiple attribute values in a feature’s label. Using Field Calculator, you can combine them into multi-line labels. All you need is to combine the fields with the || operator and add ‘\n’ (newline) wherever there should be a line break:

Field1 || '\n' || Field2

Populating a multi-line label field using Field Calculator

And finally, the result:

Multi-line labels displaying city name and population

  1. ASSA said:

    Field1 || ‘\n’ || Field2

    • underdark said:

      Thanks! You’re right, I should have added a simple case example.

  2. rdalton said:

    Thanks for the nice tutorial. I have been trying to figure out how to do that for a while. Hopefully in the future QGIS will have the ability to build a user-defined a label expression (in ArcGIS terminology) where we can concatenate multiple fields on-the-fly in memory space instead of writing it directly to the table. In the meantime, though, this is a very nice, workable solution.

  3. mattwigway said:

    In 1.7 final, ‘Multiline labels’ is under Layer Properties -> Labels -> Label Properties -> Basic label options.

    Thanks for the tip!

  4. guest said:

    Thanks for this great info! Fabulous!

  5. mattwigway said:

    Better yet, rather than creating a column that needs to be manually updated with Field Calculator when data changes, create a view in PostGIS, like so:

    CREATE VIEW labeled_stops AS SELECT stop_id || E'\r\n' || stop_name as stop_label, * from stops;

    The E’\r\n’ is Postgres’ way of saying escaped newline.

    • underdark said:

      Thanks! That’s great if you’re using PostGIS already. Maybe even a reason to migrate.

  6. mattwigway said:

    There is now an official way to do this in QGIS master (ec569a4). Works like a charm.

  7. guillaume said:

    Thanks, it helps me a lot.

%d bloggers like this: