Label alignment

cld anyone let me know how it works to get the desired label placement for the opened SHP file into QGIS 2.0.1- Dufo

  • 1
    what makes the second one more expected than the first?
    – Ian Turton
    Feb 26 '14 at 14:42

The placement is not incorrect, just your understanding of what alignment does. The alignment in the labeling engine sets the justification of multiline labels. The label is however still placed at the label point individually for each feature. Alignment (justification) only works per feature and does not justify all labels for all features against each other (that would almost never make any sense, even in your example given the two vertical lines).

If I understand it, you are wanting to align your labels to the feature. There are options for aligning relative to a point but for a line feature, you will need to use the data defined placement (on the Placement tab). Here you will see the basic placement options (Above line, On Line etc) and the next section will allow you to set a definite position at which the label will be placed. To align to the start or end (or exact middle) of the line you can use an expression. Expand the drop-down menu for the X or Y coordinate and choose Expression->Edit. For the start of the line set the expression for the X coordinate to xat(0) and the Y coordinate to yat(0). For the end of the line set the X coordinate to xat(-1) and the Y coordinate to yat(-1). (for the middle of the line use $X and $Y (though this is the default).

The above will align the label to the feature (and you can use other options or more creative expressions to adjust the label point including its rotation). However, if you want to align the labels to a whole heap of features relative to each other (which seems to be what you are requesting from your example), then you will need to set an actual coordinate value (in your case for the X coordinate) rather than $X or xat() and this coordinate will be the same for all the features whose labels you want to align together.

  • Thank you MappaGnosis, got it right now with your answer and thank you once again for your explanation about what alignment does.
    – user27395
    Feb 27 '14 at 10:54

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.