4.4.1 Vertical spacing inside a system

The height of each system is determined in two steps. First, all of the staves are spaced according to the amount of space available. Then, the non-staff lines (eg. lyrics or chords) are distributed between the staves.


Spacing between staves

Spacing between staves is controlled by the next-staff-spacing property of the VerticalAxisGroup grob. This property is an alist with four elements: space, minimum-distance, padding and stretchability:

#(set-global-staff-size 16)
\new StaffGroup <<
  % Since space is small and there is no minimum-distance, the distance
  % between this staff and the next will be determined by padding.
  \new Staff \with {
    \override VerticalAxisGroup #'next-staff-spacing =
      #'((space . 1) (padding . 1))
  }
  { \clef bass c, }
  % Since space is small and nothing sticks out very far, the distance
  % between this staff and the next will be determined by minimum-distance.
  \new Staff \with {
    \override VerticalAxisGroup #'next-staff-spacing =
      #'((space . 1) (minimum-distance . 12))
  }
  { \clef bass c, }
  % By setting padding to a negative value, staves can be made to collide.
  \new Staff \with {
    \override VerticalAxisGroup #'next-staff-spacing =
      #'((space . 4) (padding . -10))
  }
  { \clef bass c, }
  \new Staff { \clef bass c, }
>>

[image of music]

In orchestral and other large scores, it is common to place staves in groups. The space between groups is typically larger than the space between staves of the same group. This spacing can be tweaked with the StaffGrouper grob: the default value of next-staff-spacing for VerticalAxisGroup is a callback function which operates by searching for a StaffGrouper grob containing the staff. If it finds a StaffGrouper grob and the staff in question is in the middle of a group, it reads the between-staff-spacing property of StaffGrouper and returns it. If the staff in question is the last staff of a group, the callback reads the after-last-staff-spacing property of StaffGrouper and returns it. If the callback did not find a StaffGrouper grob, it reads default-next-staff-spacing from its VerticalAxisGroup and returns that.

#(set-global-staff-size 16)
<<
  \new PianoStaff \with {
    \override StaffGrouper #'between-staff-spacing #'space = #1
    \override StaffGrouper #'between-staff-spacing #'padding = #0
    \override StaffGrouper #'after-last-staff-spacing #'space = #20
  }
  <<
    \new Staff c'1
    \new Staff c'1
  >>

  \new StaffGroup \with {
    \override StaffGrouper #'between-staff-spacing #'space = #1
    \override StaffGrouper #'between-staff-spacing #'padding = #0
  }
  <<
    \new Staff c'1
    \new Staff c'1
  >>
>>

[image of music]


Spacing of non-staff lines

After the positions of the staves are determined, the non-staff lines are distributed between the staves. Each of these lines has a staff-affinity property which controls its vertical alignment. For example,

\new Lyrics \with { \override VerticalAxisGroup #'staff-affinity = #DOWN }

creates a lyrics context that will be placed close to the staff below it. Setting staff-affinity to something which is not a number (#f, for example) will cause that line to be treated like a staff. Conversely, setting staff-affinity for a staff will cause it to be treated like a non-staff.

Non-staff lines admit three properties to control their spacing. Each of the these properties is an alist of the same format as next-staff-spacing, above.

#(set-global-staff-size 16)
\layout {
  \context {
    \Lyrics
    % By default, Lyrics are placed close together. Here, we allow them to
    % be stretched more widely.
    \override VerticalAxisGroup
      #'inter-loose-line-spacing #'stretchability = #1000
  }
}

\new StaffGroup
<<
  \new Staff \with {
    \override VerticalAxisGroup #'next-staff-spacing = #'((space . 30)) }
    { c'1 }
  \new Lyrics \with {
    \override VerticalAxisGroup #'staff-affinity = #UP }
    \lyricmode { up }
  \new Lyrics \with {
    \override VerticalAxisGroup #'staff-affinity = #CENTER }
    \lyricmode { center }
  \new Lyrics \with {
    \override VerticalAxisGroup #'staff-affinity = #DOWN }
    \lyricmode { down }
  \new Staff
    { c'1 }
>>

[image of music]

See also

Snippets: Spacing.

Internals Reference: VerticalAxisGroup, VerticalAlignment, Axis_group_engraver.

Known issues and warnings

Adjacent non-staff lines should have non-increasing staff-affinity from top-to-bottom. For example, the behavior of

<<
  \new Staff c
  \new Lyrics \with { \override VerticalAxisGroup #'staff-affinity = #DOWN }
  \new Lyrics \with { \override VerticalAxisGroup #'staff-affinity = #UP }
  \new Staff c
>>

is undefined.

A non-staff line at the bottom of a system should have staff-affinity set to UP. Similarly, a non-staff line at the top of a system should have staff-affinity set to DOWN.


Más nyelvek: deutsch, español.

LilyPond — Notation Reference