19

I would like to place the elevation-number of a point in a different front size and centred under its name:

enter image description here

Is that possible?

(That is my actual labeling: label || '\n' || elevation)

5 Answers 5

13

You can achieve what you want using Rule-Based Labeling, but you need to separate the labels located in one field into two fields. Rule-Based Labeling option enables you to add labels from different fields and customize them as you like by changing font name, color, size and use offset to place them above each other.

As you can see in the example below, I put the Japanese labels and English Labels into two fields and then controlled the appearance of each label as I wanted to be:

enter image description here

To do this:

  • Go to Layer properties -> Labels
  • Select Rule-Based Labeling

enter image description here

  • Define the fields that you want to use in the labeling, each one separately. In this example, I used Name_JP and Name_EN.
  • Use the style for each one independently and customize each one as you like.
  • The most important is to use Offset under Placement for the one of the labels so that they can be above each other. For the first label field I used the following placement settings:

enter image description here

For the second label field I used the following settings:

enter image description here

Tested on QGIS 3.0.1, But it can also applied in QGIS 2.18 because Rule-Based Labeling option is available.

12

Ignoring font size for the minute, you could achieve your first option by centering the label above the point, in QGIS 1.9 you have the option to center the text under the multiple lines section. If you have included a newline character in your expression you can leave the 'Wrap on character' box empty (or I put a slash in my expression instead of the '\n' and set that as the wrap-character - the wrap-character isn't shown). This will set your text centered as in your second option. For something like your first option, you could set the line height option to 2 or 3.

However, QGIS advanced labeling only has a single option for font size. So, to achieve the different font sizes, I think you will have to add your layer a second time and set the elevation font and position in there.

4
  • 1
    Are there any current or future plans to implement the use of HTML-based font tags for QGIS labels, much like ArcGIS text formatting tags? Jan 18, 2013 at 16:01
  • 2
    @RyanDalton hub.qgis.org/issues/4080 It's a good idea, but may slow the label rendering down, and may be difficult to figure the appropriate size of the label (since that's based off of QFontMetricsF now), but have to try to implement it first to know for sure. No plans for 2.0, but might be doable for 2.1.
    – dakcarto
    Jan 18, 2013 at 17:32
  • 1
    Any news on that?
    – MartinMap
    Nov 9, 2016 at 8:18
  • Is it possible do this on QGIS 3.6?
    – Denilson
    Sep 23, 2019 at 16:36
3

Unfortunately, this is not possible yet. For a related recent discussion check http://osgeo-org.1560.x6.nabble.com/HTML-tags-in-label-expresion-on-QGIS-2-0-1-td5084946.html.

There is also an existing feature request.

2

I used a duplicate of the same layer and labelled both with placements above and under respectively after checking 'show all labels and features for all layers'as attached and it works!

0

This should be achieved using fonts symbols markers with the label background settings.

Unfortunately, there is a bug in the Characters Expressions… The fields datas are not rendered. The bug report explains in details how to proceed. https://github.com/qgis/QGIS/issues/36944

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.