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.
You need to use
wordwrap() in labeling the field as follows:
wordwrap( "Fieldname" ,number) # example: wordwrap( "Name_2" ,5)
Fieldname is the name of the target field, and
Number is the desired length of characters to wrap the string
You should place it under
Label with as in the following image:
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.
The result can be seen in image 2
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.