3

Is it possible to create a dashed underline for labeling in QGIS? I have one capital city which for used underline for the name of this city. and now I need dashed underline to a name of the province, how to create dashed underline for the name of the cities in qgis?

  • According to gis.stackexchange.com/questions/158810/… (bottom comment) dashed underlines are no option in QGIS 2.x. Maybe QGIS 3 can help you out. Or you use the print composer and label each province manually. – Erik Mar 20 '18 at 8:33
8

Here is a workaround for 2.x.

Having a point shape-file with an attribute city you can label the cities like:

 "city"  || '\n' ||  rpad( '-', length("city") + 5,  '-')

BEST FIT - additional lpad (extend to the left) without addition of a distinct value:

"city"  || '\n' ||  rpad('-',length("city"),'-') ||  lpad('-',length ("city"),'-')

First argument is the city name, then follows a line break, then we us a hypen and extend (rpad and/or lpad) it with the length of the city names (length("city") and/or add a distinct value to stretch the concatenation of hyphens.

enter image description here

EDIT - Using other Unicode characters

You could also use Unicode symbols directly (see https://gis.stackexchange.com/a/90126). Using a fullwidth hyphen-minus from http://jkorpela.fi/dashes.html (lowermost entry in the first column of the table), the dashed line looks even better. Just copy/paste it in the Expression Dialog. I've shortened it a little bit (-2).

"city"  || '\n' ||  rpad('-',length("city")-2, '-')

enter image description here

Label lookalike with katakana-hiragana double hyphen:

enter image description here

Additionally you have to decrease the line height in the Labels > Formatting. So the dash line is closer to the city name. Also use Center as Alignment to center both lines.

Usage in the Layer Properties:

enter image description here

Result

enter image description here

I think you have to play around a little bit with the distinct value for stretching the concatenation of hyphens.

EDIT

If there is an attributes that distinguish if the city is a capital or not then you can use Rule-based labeling.

In my case I have an attribute table as follows:

enter image description here

Rule-based labeling in this case:

enter image description here

Result (cities which are not capitals have a normal underline (defined within in the label settings):

enter image description here

1

You can probably achieve it by using an SVG label background (Shape in the dialog) and constructing the SVG in a way that the end result appears as a dashed line.

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.