1

This question already has an answer here:

I have a long text in one attribute field and want to place it as a label. Because the text is so long I want to divide it in two rows. How to do that using QGIS. I have a solution to divide text in two fields and make multi labeling, but I don't want that.

marked as duplicate by underdark qgis Nov 6 '17 at 22:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq. – underdark Nov 6 '17 at 22:16
5

You need to use wordwrap() in labeling the field as follows:

 wordwrap(  "Fieldname" ,number)         # example:  wordwrap(  "Name_2" ,5)

where:

Fieldname is the name of the target field, and Number is the desired length of characters to wrap the string

enter image description here

You should place it under Label with as in the following image:

enter image description here

4

The third option is to define a certain character or multiple characters as a wrapping point.

You can do This under layer properties -> Labels -> Formatting. You will find an option called "Warp on character" here you define your character. You need to take to use such characters which are not used somewhere else. In the image 1, I use the "--" as warp character.

Image 1 shows the option

The result can be seen in image 2

Image 2 shows the result

0

You can write an expression and insert a newline character where you want to wrap the text onto a new line. One of my layers uses a formula that pulls together six fields to create the label.

if(coalesce("caption" ,'') = '', '', "caption" || '\n') || trim(concat("Distance",' ', "Unit", ' ', "Label", ' ',"Distance 2",' ', "Unit 2", ' ',"Label 2", ' '))

the first part (coalesce) is dealing to null propagation and ensuring there isn't a blank top line if the first field is empty. I haven't quite got to dealing the possibility of a blank 2nd line.

Not the answer you're looking for? Browse other questions tagged or ask your own question.