2

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
    Commented Feb 9, 2023 at 11:58

2 Answers 2

2

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. Commented Feb 10, 2023 at 9:21
  • You would need to find the appropriate A factor to have constant margins, I believe.
    – Kasper
    Commented Feb 10, 2023 at 18:05
1

This is solvable if you use HTML rendering to create a table cell with CSS "background-color","color" and "padding" style:

enter image description here

<table><tr><td style="padding:5 20;background-color:blue;color:white">[% my_title_field %]</td></tr></table>

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.