5

I'm using QGIS 2.14.3.

It is now possible to assign different colors (or fonts) to different parts of text in one label (I have seen How to make a different font and color of text in labels? )? If so, how?

Example


Although not perfect, @Knightshound 's comment provided a workaround solution I am happy with so far: Using multiple rule-based labelling without expression rules and assigning Offset from point placements in order to achieve required result.

Result

  • Have a look at this post: What's wrong with my expression to control label colors? – Joseph Jun 2 '16 at 12:35
  • This does not really help since it colors the whole label when I would like to color only parts of it. – Victor Jun 2 '16 at 12:38
  • Ahh gotcha! Not something I've tried so would be interesting to see if it is indeed possible =) – Joseph Jun 2 '16 at 12:45
  • Still not possible in Qgis as your linked question stated. Nothing changed. – Matte Jun 2 '16 at 12:58
  • Even with some python? – Victor Jun 2 '16 at 13:05
3

Expanding on my comment, start off by getting the different sections of the label you wish to be in different colours/fonts into separate columns in the attribute table. In the layer properties "Labels" tab choose "Rule-based labeling' from the drop-down. Now for the slightly tricky part.

Create a new rule for every word you want to be different. In the "Edit Rule" window "Placement" tab, select 'Around Point'. This bit is now trial and error to find the perfect layout, but using the data defined override for the quadrant (number between 0-8 depending on location, hover over button to see) and specifying a distance away from the point you can quite nicely line up several pieces of text into what appears to be a single string. If you find your labels are disappearing because of overlap, under the "Rendering tab" check 'Show all labels for this layer (including colliding labels)'.

And just to make things a little tidier/easier to manage, when creating your rules try nesting them (drag and drop a rule onto another rule). This way any words that you use repeatedly can still be given a style without having to write a more complex rule. In the print screen below I created a rule based on the ID. I then nested the rule I used for the word 'the' without having to change the rule (as you can see with 'the dog' rule where I had to specify that "t1" = 'the' AND "t2" = 'dog' so that the right 'the' was being chosen). Just remember not to add a label to this parent rule as you will then get duplicate labels popping up.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.