Q:

How to make labels in a fixed position for a road layer in QGIS 3.2

I am working on a road layer containing hundreds of roads and want to print it out in a A2 size with all labels. I want the labels to be fixed in the original position and not depend on scaling of the map. Is there a solution? 

A:

Data-defined label placement

To position the labels at the centroid of the line, use these expressions 

X coordinate: x(centroid($geometry))
Y coordinate: y(centroid($geometry))

To position the labels at the midpoint of the line, use these expressions:

X coordinate: x(line_interpolate_point( $geometry, distance_to_vertex($geometry, num_points($geometry)-1)/2))
Y coordinate: y(line_interpolate_point( $geometry, distance_to_vertex($geometry, num_points($geometry)-1)/2))

You can write different expressions to adjust the label position how you like.

Data-defined label orientation
Unfortunately, using data-defined label placement overrides the label orientation setting. The labels will revert to horizontal placement, regardless of what orientation setting (parallel/curved/horizontal) you choose.

So if you want the label oriented any way other than horizontal, you have to write another expression to control the label orientation. This expression will give you labels that are parallel to the midpoint of the line. (Use it with the expressions for placing labels at the midpoints.)
line_interpolate_angle( $geometry, distance(  start_point( $geometry),line_interpolate_point( $geometry, distance_to_vertex($geometry, num_points($geometry)-1)/2)))-90

As you can see it's not 100% perfect.

Bonus Tip:  If you want the labels to always be the same size relative to the other items on the map, define the font size in map units.

