3

I'm working on a map in QGIS (3.16.11-Hannover) and have a feature label that's generated from three attributes as follows:

"Site name"   || ', ' ||  "When" ||   '\n'   || "Comment" 

I'd like to bold and/or underline the first line (i.e. the two attributes "Site name" and "When") as a sub-heading, but leave the rest (the "Comment" attribute, which is a relatively long description in this case) unbolded. Is there a way to do this or can I only bold the whole heading or not at all.

I tried setting this up in the bold formatting by field dropdown (see below), but this seems to bold the entire label when it contains the text in that field, which is not what I want.

screenshot of bold formatting by field dropdown

I did come across this similar question here but I believe that's to allow only some labels in a feature to be bolded, rather than only one part of the label for every feature.

By the way, I'm aware that putting this much text on a map usually isn't great design but I think what I'm trying to do here is a legitimate exception!

3
  • 4
    Here is a solution creating SVG's on the fly and using them as the label...
    – JGH
    Commented Jan 25, 2022 at 20:49
  • 4
    And gis.stackexchange.com/questions/357234/… is a hack via expressions and unicode characters. Commented Jan 25, 2022 at 21:12
  • Thanks both. Erik's solution below worked better for my purposes but these are both useful alternatives. Appreciate your help.
    – TimM
    Commented Jan 27, 2022 at 4:35

1 Answer 1

1

Possible workaround:

Duplicate your layer. Label the original layer with the name of the site in bold. Label the second layer with your other attributes in normal script, start the label with an empty row. Use identical, fixed label placements for both layers. Finally, turn off the symbology on the duplicated layer.

You could also look into text markers as symbology.

5
  • Thanks for this. I actually had a similar idea and discounted it as too much hassle, but it wasn't too bad actually. A few little tips for anyone else who reads this and gives it a go (in multiple comments due to length). 1. as Erik says, make sure you use the 'duplicate layer' option rather than saving it as a new layer. That way, if you need to move the labels around manually later they'll move together (the second one will move when you save the layer and update the attributes)
    – TimM
    Commented Jan 27, 2022 at 4:30
  • 2. if, like mine, your labels go over multiple rows and aren't of equal length, you'll need to add empty rows to make them line up. Otherwise the header rows end up in the wrong place. I fixed this by adding "*" manually to the end of the header row and putting that in the "wrap on character" field under labels/formatting (you could also add lines to the 'body' of the label but I found this messes up callouts, if you have them).
    – TimM
    Commented Jan 27, 2022 at 4:31
  • 3. There's probably a more elegant solution to that second issue involving a python if() statement and the length() function but I only had 10-15 rows of data so doing it the hacky way was way quicker for my purposes. All that aside, thanks for your help Erik (and everyone else above)
    – TimM
    Commented Jan 27, 2022 at 4:34
  • @TimM you may also use '\n' for breaks.
    – Erik
    Commented Jan 27, 2022 at 8:22
  • Thanks Erik - yes I'm aware of that, but don't think it works by default in feature labels. I could be wrong.
    – TimM
    Commented Jan 28, 2022 at 8:44

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.