TransWikia.com

Underline labels in different color using QGIS

Geographic Information Systems Asked by Léo Mazel on July 20, 2021

Is it possible to underline a label in a different color than the one used to write the said label using QGIS?

In my case, I would like to underline some countries’ names, which are in black, in red. Here is how I would like it to look like:

enter image description here

2 Answers

It's possible but it's a bit messy.

The overall idea is to add a background rectangle that is squashed vertically so much that it's just a horizontal line, and then offset downwards so it looks like its an underline. Then just colour the background outline a different colour like red.

To do this I went to the background tab in Labels and I used the following settings:

  • Shape = Rectangle
  • Size X = 0
  • Size Y = -1.9
  • Offset X,Y = 0, 2.2
  • Stroke colour = red

You might have to play around with the sizes and offsets depending on your label size and font. For me I used MS Shell Dlg 2 at size 9 points and it ended up looking like this: enter image description here

You can then add a conditional expression for the stroke colour if you want different labels to have different colour underlines.

Also the obvious downside of this is that it impacts your ability to add a background if you want one. It would probably be possible but it would be harder to do.

Answered by TeddyTedTed on July 20, 2021

The other answer, with a coloured squashed background, is probably your best bet.

Alternatively, with some effort you could probably achieve what you want by constructing embedded SVG to use as your label, including both your desired label text as well as the target underline. As a starting point, see the answer to QGIS Labels with HTML formating, where it is developed for a different use case (emulating HTML) but gives some ideas.

Note QGIS does offer HTML formatting of labels, but currently only text colour is implemented, so it won't solve your problem directly.

Answered by Houska on July 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP