Grob sizing

In general, all grobs support the grob-interface, which contains, among other things, the properties X-offset, Y-offset, X-extent, and Y-extent (see Offsets and alignments for a thorough introduction).

By default, outside-staff objects are given a width (i.e., a horizontal extent) of zero so that they may overlap in the horizontal direction. By convention, this is done by positioning a grob’s left edge at infinity and the right edge at minus infinity by setting the extra-spacing-width property to '(+inf.0 . -inf.0). To ensure grobs do not overlap in the horizontal direction we must override this value of extra-spacing-width to give them a little extra spacing. The units are the space between two staff lines, so moving the left edge half a unit to the left and the right edge half a unit to the right should do it:

\override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)

Let’s see whether this works in our previous example:

% Extend width by 1 staff space
\override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
\relative { a'4\f b\mf a\mp b\p }

[image of music]

This looks better, but maybe we would prefer the dynamic marks to be aligned along the same baseline rather than going up and down with the notes. The property to do this is staff-padding, which is covered in the section on collisions (see Collisions of objects).

LilyPond Learning Manual v2.25.17 (development-branch).