In this question I was able to align some labels with polylines representing hectometer points along a railroad. I did this using custom expressions in the "data defined" portion of the labelling tab in the layer properties:
The problem now is that the label spacing with respect to the line end points is zoom dependent. Here's a zoomed in portion of the map:
Here's the same portion of the map, zoomed out:
This is kind of a problem when it comes to making layouts, as usually you want to have separate layouts coming from the same canvas to have slightly different zoom labels but to be consistent when it comes to symbology.
Perhaps one way to overcome this issue is by specifying canvas units for the offset rather than map units in the X and Y portions of the data defined section in the Layer Properties Dialog:
X: x(end_point($geometry))+5*canvas_units
Y: y(end_point($geometry))+3*canvas_units
But I'm not sure whether this is possible. If anyone has any idea how to do this please let me know. Thanks.


