+@node Flexible vertical spacing within systems
+@subsection Flexible vertical spacing within systems
+
+@cindex distance between staves
+@cindex staff distance
+@cindex space between staves
+@cindex space inside systems
+
+Three separate mechanisms control the flexible vertical spacing
+within systems, one for each of the following categories:
+
+@itemize
+
+@item
+@emph{ungrouped staves},
+
+@item
+@emph{grouped staves} (staves within a staff-group such as
+@code{ChoirStaff}, etc.), and
+
+@item
+@emph{non-staff lines} (such as @code{Lyrics}, @code{ChordNames},
+etc.).
+
+@end itemize
+
+@c TODO: Clarify this. This almost implies that non-staff lines
+@c have NO effect on the spacing between staves. -mp
+
+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 are distributed between the
+staves.
+
+Note that the spacing mechanisms discussed in this section only
+control the vertical spacing of staves and non-staff lines within
+individual systems. The vertical spacing between separate
+systems, scores, markups, and margins is controlled by
+@code{\paper} variables, which are discussed in
+@ref{Flexible vertical spacing paper variables,,Flexible vertical spacing @code{@bs{}paper} variables}.
+
+@menu
+* Within-system spacing properties::
+* Spacing of ungrouped staves::
+* Spacing of grouped staves::
+* Spacing of non-staff lines::
+@end menu
+
+
+@node Within-system spacing properties
+@unnumberedsubsubsec Within-system spacing properties
+
+@funindex staff-affinity
+@funindex staffgroup-staff-spacing
+@funindex staff-staff-spacing
+@funindex nonstaff-unrelatedstaff-spacing
+@funindex nonstaff-relatedstaff-spacing
+@funindex nonstaff-nonstaff-spacing
+@funindex default-staff-staff-spacing
+@funindex minimum-Y-extent
+@funindex extra-offset
+@funindex self-alignment-X
+@funindex X-offset
+@funindex VerticalAxisGroup
+
+The within-system vertical spacing mechanisms are controlled by
+two sets of grob properties. The first set is associated with the
+@code{VerticalAxisGroup} grob, which is created by all staves and
+non-staff lines. The second set is associated with the
+@code{StaffGrouper} grob, which can be created by staff-groups,
+but only if explicitly called. These properties are described
+individually at the end of this section.
+
+The names of these properties (except for @code{staff-affinity})
+follow the format @code{@var{item1}-@var{item2}-spacing}, where
+@code{@var{item1}} and @code{@var{item2}} are the items to be
+spaced. Note that @code{@var{item2}} is not necessarily below
+@code{@var{item1}}; for example,
+@code{nonstaff-relatedstaff-spacing} will measure upwards from the
+non-staff line if @code{staff-affinity} is @code{UP}.
+
+Each distance is measured between the @emph{reference points} of
+the two items. The reference point for a staff is the vertical
+center of its @code{StaffSymbol} (i.e. the middle line if
+@code{line-count} is odd; the middle space if @code{line-count} is
+even). The reference points for individual non-staff lines are
+given in the following table:
+
+@multitable {Non-staff line} {Reference point}
+@headitem Non-staff line @tab Reference point
+@item @code{ChordNames} @tab baseline
+@item @code{NoteNames} @tab baseline
+@item @code{Lyrics} @tab baseline
+@item @code{Dynamics} @tab mid-height of @q{m}
+@item @code{FiguredBass} @tab highest point
+@item @code{FretBoards} @tab top line
+@end multitable
+
+In the following image, horizontal lines indicate the positions
+of these reference points:
+
+@lilypond[quote,noragged-right,line-width=110\mm]
+#(define zero-space '((padding . -inf.0) (basic-distance . 0)))
+
+alignToZero = \with {
+ \override VerticalAxisGroup.nonstaff-relatedstaff-spacing = #zero-space
+ \override VerticalAxisGroup.nonstaff-nonstaff-spacing = #zero-space
+ \override VerticalAxisGroup.staff-affinity = #DOWN
+ \remove Text_engraver % avoid having two
+ \consists Text_engraver
+}
+lowerCaseChords = \with {
+ chordNameLowercaseMinor = ##t
+}
+labelContext =
+#(define-music-function
+ (parser location context)
+ (string?)
+ #{ s1*0^\markup { \upright {\typewriter #context } } #})
+
+\layout {
+ \context { \Dynamics \alignToZero }
+ \context { \FiguredBass \alignToZero }
+ \context { \Lyrics \alignToZero }
+ \context { \NoteNames \alignToZero }
+ \context { \ChordNames \alignToZero \lowerCaseChords }
+ \context { \FretBoards \alignToZero }
+ \context { \Score
+ \omit BarLine
+ \override DynamicText.self-alignment-X = #-1
+ \override FretBoard.X-offset = #1.75
+ \override InstrumentName.minimum-Y-extent = #'(-1 . 2)
+ \textLengthOn
+ \omit TimeSignature
+ }
+}
+
+%% These contexts have reference points at the baseline:
+%% ChordNames, NoteNames, and Lyrics
+<<
+ \new ChordNames { \chords { \labelContext "ChordNames" g1:m } }
+ \new NoteNames { s1 |\labelContext "NoteNames" g1 | }
+ \new Lyrics { \lyrics { \skip 1*2 | \labelContext "Lyrics" ghijk1 | } }
+ \new RhythmicStaff \with { instrumentName = #"baseline " } s1*3
+>>
+
+%% The reference point for Dynamics is the midline of 'm' in the font
+<<
+ \new Dynamics { \labelContext "Dynamics" s1\mp s\fp }
+ \new RhythmicStaff \with { instrumentName = #"mid-height " } s1*3
+>>
+
+%% The reference point for FiguredBass is its highest point
+<<
+ \new FiguredBass { \labelContext "FiguredBass" \figuremode { <6 5>1 } }
+ \new RhythmicStaff \with { instrumentName = #"highest point " } s1
+>>
+
+%% The reference point for FretBoards is the top line
+\include "predefined-guitar-fretboards.ly"
+<<
+ \new FretBoards { \labelContext "FretBoards" \chordmode { e1 } }
+ \new RhythmicStaff \with { instrumentName = #"top line " } s1
+>>
+@end lilypond
+
+Each of the vertical spacing grob properties (except
+@code{staff-affinity}) uses the same alist structure as the
+@code{\paper} spacing variables discussed in
+@ref{Flexible vertical spacing paper variables,,Flexible vertical spacing @code{@bs{}paper} variables}.
+Specific methods
+for modifying alists are discussed in @ref{Modifying alists}.
+Grob properties should be adjusted with an @code{\override} inside
+a @code{\score} or @code{\layout} block, and not inside a
+@code{\paper} block.
+
+The following example demonstrates the two ways these alists can
+be modified. The first declaration updates one key-value
+individually, and the second completely re-defines the property:
+
+@example
+\new Staff \with @{
+ \override VerticalAxisGroup.default-staff-staff-spacing.basic-distance = #10
+@} @{ @dots{} @}
+
+\new Staff \with @{
+ \override VerticalAxisGroup.default-staff-staff-spacing =
+ #'((basic-distance . 10)
+ (minimum-distance . 9)
+ (padding . 1)
+ (stretchability . 10))
+@} @{ @dots{} @}
+@end example
+
+To change any spacing settings globally, put them in the
+@code{\layout} block: