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


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? – Enzo Baldini Sep 16 '20 at 17:31
  • You have to select the layer in the legend dialog like in my case. – christoph Sep 16 '20 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. – Enzo Baldini Sep 16 '20 at 17:34
  • Yes, you are right. That‘s totally different... sorry, didn‘t look close enough. – christoph Sep 16 '20 at 17:38
  • I guess it's not possible at the moment. You could post a change request in Github. – christoph Sep 16 '20 at 18:08

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.