lilypond-learning: Grob sizing
Grob sizing
...........
First we must learn how grobs are sized. All grobs have a reference
point defined within them which is used to position them relative to
their parent object. This point in the grob is then positioned at a
horizontal distance, ‘X-offset’, and at a vertical distance, ‘Y-offset’,
from its parent. The horizontal extent of the object is given by a pair
of numbers, ‘X-extent’, which say where the left and right edges are
relative to the reference point. The vertical extent is similarly
defined by a pair of numbers, ‘Y-extent’. These are properties of all
grobs which support the ‘grob-interface’.
By default, outside-staff objects are given a width of zero so that
they may overlap in the horizontal direction. This is done by the trick
of making the leftmost extent infinity and the rightmost extent minus
infinity by setting the ‘extra-spacing-width’ to ‘'(+inf.0 . -inf.0)’.
To ensure they 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 if this works in our previous example:
\dynamicUp
% Extend width by 1 staff space
\override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
a4\f b\mf a\mp b\p
[image src="" alt="[image of music]" text="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).