4.5.1 Horizontal spacing overview

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 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.

\relative c' {
  c2 c4. c8
  c4. c8 c4. c8
  c8 c c4 c c
}

[image of music]

Normally, spacing-increment is set to 1.2 staff space, which is approximately the width of a note head, and shortest-duration-space is set to 2.0, meaning that the shortest note gets 2.4 staff space (2.0 times the spacing-increment) of horizontal space. This space is 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 32nd 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 rather the one which occurs most frequently.

The most common shortest duration is determined as follows: in every measure, the shortest duration is determined. The most common shortest duration is taken as the basis for the spacing, with the stipulation that this shortest duration should always be equal to or shorter than an 8th note.

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 an 8th), is set through base-shortest-duration.

Notes that are even shorter than the common shortest note 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:

\relative { c''2 c4. c8 | c4. c16[ c] c4. c8 | c8 c c4 c c }

[image of music]

As explained in the Essay on automated music engraving, stem directions will influence spacing (see Optical spacing) and can be adjusted using the stem-spacing-correction property of the NoteSpacing object (which are generated for every Voice context).

The StaffSpacing object (generated in Staff context) contains the same property for controlling the stem/bar line spacing.

The following example shows this; once with the default settings and once with an exaggerated adjustment:

[image of music]

Proportional notation is supported; see Proportional notation.

See also

Essay on automated music engraving: Optical spacing.

Snippets: Spacing.

Internals Reference: SpacingSpanner, NoteSpacing, StaffSpacing, NonMusicalPaperColumn.

Known issues and warnings

There is no convenient mechanism to manually override spacing. The following workaround may be used to insert extra space into a score, adjusting the padding value as necessary.

 \override Score.NonMusicalPaperColumn.padding = #10

No workaround exists for decreasing the amount of space.


LilyPond — Notation Reference v2.24.4 (stable-branch).