I want to wrap legend text after a certain amount of characters. Is there an automatic way to do that?

I don't want to enter a character (e.g. *) for each line as described in this post, that is too much work...

enter image description here

Edit: I tried to use an expression, but the button is greyed out...

enter image description here

2 Answers 2


You could use an expression string for your labels:

enter image description here

with_variable( 'column',37,
   if(length(@symbol_label) > @column,
      regexp_replace(left(@symbol_label,@column),'(.+)([\\s,;\\.])([^\\s,;\\.]+)$','\\1\\2\n\\3') + substr(@symbol_label,@column+1),@symbol_label))

Without expression string: enter image description here

With expression string: enter image description here

  • thank you for your answer. do you have an idea why the epsilon-button is greyed out in my case? Commented Sep 16, 2020 at 17:31
  • You have to select the layer in the legend dialog like in my case.
    – christoph
    Commented Sep 16, 2020 at 17:33
  • I did. But it is a raster layer and you have a vector layer. And I am using the styles of a qml-file. Maybe that is why? I edited my question and added another screenshot. Commented Sep 16, 2020 at 17:34
  • Yes, you are right. That‘s totally different... sorry, didn‘t look close enough.
    – christoph
    Commented Sep 16, 2020 at 17:38
  • I guess it's not possible at the moment. You could post a change request in Github.
    – christoph
    Commented Sep 16, 2020 at 18:08

Since QGIS 2.4 you can use wordwrap function.

For 50 characters it would be like this:

wordwrap(@symbol_label, 50)

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.