0

In the layout composer I want to add a title in black text with a white background.

My title will be dynamic and I want the text box ("label" in the composer) to automatically adapt its size in order to fit the text length without needing to manually change its size.

1
  • You simply could move the label out of the map frame?
    – Erik
    Feb 9, 2023 at 11:58

1 Answer 1

1

Assuming your title text comes from a given expression (in my case I just took @layout_name)

You can set the Label's Position & Size properties X and Width to depend on your title text expression:

Set Width to be something like: A x length(title string) + B:

enter image description here

Set X to be something like: Page middle X coordinate - Width/2:

enter image description here

Here you go: enter image description here

2
  • thankyou, it's probably the closest solution. I guess there's no way to have a constant fit as the text length (which is expressed in number of characters I guess) is translated to millimeters or whatever measure i pick which differs from the actual length(text) measure. I notice in fact that with the same multiplier (even x1) a longer text will have a box wich exceed it in length more compared to a shorter text. Feb 10, 2023 at 9:21
  • You would need to find the appropriate A factor to have constant margins, I believe.
    – Kasper
    Feb 10, 2023 at 18:05

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.