Next: , Previous: Vertical spacing, Up: Global layout



4.6.3 Horizontal Spacing

The spacing engine translates differences in durations into stretchable distances (“springs”) of differing lengths. Longer durations get more space, shorter durations get less. The shortest durations get a fixed amount of space (which is controlled by shortest-duration-space in the SpacingSpanner object). The longer the duration, the more space it gets: doubling a duration adds a fixed amount (this amount is controlled by spacing-increment) of space to the note.

For example, the following piece contains lots of half, quarter, and 8th notes, the eighth note is followed by 1 note head width (NHW). The quarter note is followed by 2 NHW, the half by 3 NHW, etc.

c2 c4. c8 c4. c8 c4. c8 c8
c8 c4 c4 c4

[image of music]

Normally, spacing-increment is set to 1.2, which is the width of a note head, and shortest-duration-space is set to 2.0, meaning that the shortest note gets 2 NHW of space. For normal notes, this space is always counted from the left edge of the symbol, so the shortest notes are generally followed by one NHW of space.

If one would follow the above procedure exactly, then adding a single 32th note to a score that uses 8th and 16th notes, would widen up the entire score a lot. The shortest note is no longer a 16th, but a 32nd, thus adding 1 NHW to every note. To prevent this, the shortest duration for spacing is not the shortest note in the score, but the most commonly found shortest note. Notes that are even shorter this are followed by a space that is proportional to their duration relative to the common shortest note. So if we were to add only a few 16th notes to the example above, they would be followed by half a NHW:

 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4

[image of music]

The most common shortest duration is determined as follows: in every measure, the shortest duration is determined. The most common short duration, is taken as the basis for the spacing, with the stipulation that this shortest duration should always be equal to or shorter than 1/8th note. The shortest duration is printed when you run lilypond with --verbose. These durations may also be customized. If you set the common-shortest-duration in SpacingSpanner, then this sets the base duration for spacing. The maximum duration for this base (normally 1/8th), is set through base-shortest-duration.

In the Introduction it was explained that stem directions influence spacing. This is controlled with stem-spacing-correction property in NoteSpacing, which are generated for every Voice context. The StaffSpacing object (generated at Staff context) contains the same property for controlling the stem/bar line spacing. The following example shows these corrections, once with default settings, and once with exaggerated corrections:

[image of music]

Properties of the SpacingSpanner must be overridden from the \paper block, since the SpacingSpanner is created before any property commands are interpreted.

     \paper { \context  {
       \ScoreContext
       \override SpacingSpanner #'spacing-increment = #3.0
     } }

See also

Internals: SpacingSpanner, NoteSpacing, StaffSpacing, SeparationItem, and SeparatingGroupSpanner.

Bugs

Spacing is determined on a score wide basis. If you have a score that changes its character (measured in durations) halfway during the score, the part containing the longer durations will be spaced too widely.

There is no convenient mechanism to manually override spacing.

Read comments on this page, or add one.

This page is for LilyPond-2.2.6 (stable-branch).

Report errors to <bug-lilypond@gnu.org>.