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.

Ian Turton
84.1k6 gold badges93 silver badges190 bronze badges
asked Jul 17, 2023 at 11:35
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. Commented Jul 17, 2023 at 12:44

3 Answers 3

3

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.

answered Jul 17, 2023 at 13:30
3

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>'

answered Jul 24, 2023 at 8:22
0

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

answered Jul 18, 2023 at 1:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.