6

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?

0

2 Answers 2

8

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

 case
 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)
 end

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.

0
1

Please note that there is another option for using the delimiter in the wordwrap function as follows

Text in Field

Field1 = "Text1 \n Text2"

wordwrap syntax

wordwrap("Field1",1,'\\n')

Resulting label

Text1

Text2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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