I'm having a problem with multi-field labeling both using the 'wordwrap' function and the 'wrap on character' mode. In fact I would need to use the multiline mode only on the second of the two fields (setting the wrap_lenght to optimize the number of lines) but I have not succeeded in any way.

enter image description here

enter image description here

in the first image, on the left the correct formatting, on the right the formatting that I would like to correct but avoiding too many lines as on the right in the second image. The "number" is the first field while the "name" the second field.

I tried to solve the problem using the expression:

"FIELD_1" || '' || wordwrap ("FIELD_2", 12)

without changes in formatting, and also using a rule based labeling with:

"FIELD_1" || ''
'' || wordwrap ("FIELD_2", 12)

but completely losing the formatting.

Is it possible to solve this problem?


You can apply a condition to have more control on the labels if the length of text exceeds certain number of characters as follows:

 when  length("Field_2") < 6 then "Field_1"  || '\n' || wordwrap("Field_2",6)
 when length("Field_2") >= 6 then "Field_1"  || '\n' || wordwrap("Field_2",12)

The numbers 6 and 10 are just an example, you need to adjust them based on your needs.

The output should look like this:

enter image description here

In the above examples the length of Smith County and Bob County are different but they stacked onto two lines based on the conditions above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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