4

I use the QGIS version 3.28.4-Firenze and I have the following question: How can I label a polygon layer with two attributes, where the two attribute labels should look different (color, shape, size) and should be located exactly horizontal next to each other, but outside of the geometries I will label?

Does anyone have an idea how it could work?

this is how it looks at the moment this is how it looks at the moment

it should look like that

it should look like that


"A simple option would be to use 'offset from point' for label placement and then use different offset distances for each label."

I tried this option. You can see the result in the first picture. I was hoping to do it without Python, but maybe I should give it an try, or someone else knows a way to make the two attributes line up horizontally.

1
  • Thank you, but unfortunately my problem cannot be solved with the help of the videos. It is more complex than what is shown in the videos.
    – KittyKr
    Commented Jul 17, 2023 at 12:44

3 Answers 3

2

To get two labels you can use rule based labelling, and do not any filter for each rule, i.e. all features for each. You can style each differently.

Label placement is more tricky.

A simple option would be to use 'offset from point' for label placement and then use different offset distances for each label.

I haven't tried more complex solutions. is there a QGIS expression to find the position of a features labels? If not this post might help with a Python route.

1

You can use an expression to format your labels.

enter image description here

Rightclick on your layer and choose Properties. Go to the tab Labels.

enter image description here

  • In the dropdown-menu select Single Labels.
  • Check Allow HTML formating
  • Click on the expression button next to Value
  • Add an expression, the basics: concatenate values from 2 fields separated by ' - '

"Field1" || ' - ' || "Field2"

  • style your label with whatever color, width, etc. using html

'<h style="color:red;">' || "Field1" || '</h>' || '- ' || '<h style="color:yellow;">' || "Field2" || '</h>'

0

Concatenate the text for the two labels, then they will always be plotted together, and you will not need two labels.

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.