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):
- Create a big enough text field (if the data doesn’t contain any yet).
- In Layer Properties – Fields, chose a “Text edit” edit widget for the label field.
- Enter the multi-line text into the label field. You can do this using Attribute Table or Feature Form.
- Activate labeling. You’ll have to tick “Multiline labels” option in Layer Labeling Settings – Advanced – Options. That’s it:
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
And finally, the result:
Pingback: [QGIS 1.x] Etiquettes multi-lignes | Jeux De Fille
Field1 || ‘\n’ || Field2
Thanks! You’re right, I should have added a simple case example.
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.
In 1.7 final, ‘Multiline labels’ is under Layer Properties -> Labels -> Label Properties -> Basic label options.
Thanks for the tip!
Thanks for this great info! Fabulous!
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:
The E’\r\n’ is Postgres’ way of saying escaped newline.
Thanks! That’s great if you’re using PostGIS already. Maybe even a reason to migrate.
There is now an official way to do this in QGIS master (ec569a4). Works like a charm.
Thanks, it helps me a lot.