29.2 Explicit staff and system positioning

It is possible to approach vertical spacing in a different way (in comparison to what was demonstrated in the previous sections) by using the property line-break-system-details of the NonMusicalPaperColumn grob. While the flexible vertical spacing mechanisms specify vertical padding, line-break-system-details can specify exact vertical positions on the page.

This property contains five different subproperties: X-offset, Y-offset, extra-offset, alignment-distances, and bottom-padding.

To understand how each of these different subproperties work, we begin by looking at an example that includes no overrides at all. We isolate both line breaking and page breaking information in a dedicated voice, dividing the music into five measures per line. This technique of creating an otherwise empty voice for breaks helps in keeping layout separate from music entry as our example becomes more complicated. Also see Breaks.

\book {
  \score {
    <<
      \new Staff <<
        \new Voice {
          s1*5 \break
          s1*5 \break
          s1*5 \break }
        \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
      >>
      \new Staff { \repeat unfold 15 { d'4 d' d' d' } }
    >>
  }
}
[image of music]

We now set the vertical and horizontal start points of each system explicitly by using the Y-offset and X-offset subproperties of line-break-system-details.

\book {
  \score {
    <<
      \new Staff <<
        \new Voice {
          \once \override
            Score.NonMusicalPaperColumn
                 .line-break-system-details.Y-offset = 0
          s1*5 \break
          \once \override
            Score.NonMusicalPaperColumn
                 .line-break-system-details.Y-offset = 30
          \once \override
            Score.NonMusicalPaperColumn
                 .line-break-system-details.X-offset = 10
          s1*5 \break
          \once \override
            Score.NonMusicalPaperColumn
                 .line-break-system-details.Y-offset = 50
          s1*5 \break }
        \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
      >>
      \new Staff { \repeat unfold 15 { d'4 d' d' d' } }
    >>
  }
}
[image of music]

In contrast to the absolute positioning available through Y-offset and X-offset, relative positioning is possible with the extra-offset subproperty. Placement is relative to the default layout or to the absolute positioning created by setting X-offset and Y-offset. The subproperty extra-offset accepts a pair consisting of displacements along the X- and Y-axis.

\book {
  \score {
    <<
      \new Staff <<
        \new Voice {
          s1*5 \break
          \once \override
            Score.NonMusicalPaperColumn
              .line-break-system-details.extra-offset = #'(5 . 5)
          s1*5 \break
          \once \override
            Score.NonMusicalPaperColumn
              .line-break-system-details.extra-offset = #'(0 . 20)
          s1*5 \break }
        \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
      >>
      \new Staff { \repeat unfold 15 { d'4 d' d' d' } }
    >>
  }
}
[image of music]

Now that we have set the vertical start point of each system explicitly, we can also set the vertical distances between staves within each system manually by modifying the alignment-distances subproperty. As can be seen, we use an alist to set two different line-break-system-details subproperties at the same time.

\book {
  \score {
    <<
      \new Staff <<
        \new Voice {
          \once \override
            Score.NonMusicalPaperColumn.line-break-system-details =
              #'((Y-offset . 0)
                 (alignment-distances . (10)))
          s1*5 \break
          \once \override
            Score.NonMusicalPaperColumn.line-break-system-details =
              #'((Y-offset . 30)
                 (alignment-distances . (15)))
          s1*5 \break
          \once \override
            Score.NonMusicalPaperColumn.line-break-system-details =
              #'((Y-offset . 65)
                 (alignment-distances . (20)))
          s1*5 \break }
        \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
      >>
      \new Staff { \repeat unfold 15 { d'4 d' d' d' } }
    >>
  }
}
[image of music]

The next example shows how to set vertical positions of multiple staves in a system. Note that alignment-distances directly applies to staves, not taking care of grouping with StaffGroup or the like. Value #f indicates that the default value should be used.

\book {
  \score {
    <<
      \new Staff <<
        \new Voice {
          \once \override
            Score.NonMusicalPaperColumn.line-break-system-details =
              #'((Y-offset . 0)
                 (alignment-distances . (15 8)))
          s1*5 \break
          \once \override
            Score.NonMusicalPaperColumn.line-break-system-details =
              #'((Y-offset . 35)
                 (X-offset . 10)
                 (alignment-distances . (#f 8)))
          s1*5 \break
          \once \override
            Score.NonMusicalPaperColumn.line-break-system-details =
              #'((Y-offset . 65)
                 (alignment-distances . (8 15)))
          s1*5 \break }
        \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
      >>
      \new StaffGroup <<
        \new Staff { \repeat unfold 15 { d'4 d' d' d' } }
        \new Staff { \repeat unfold 15 { e'4 e' e' e' } }
      >>
    >>
  }
}
[image of music]

The last subproperty of line-break-system-details, bottom-padding, has a similar effect as last-bottom-spacing. Note, however, that it doesn’t hold a compressible or stretchable spacing dimension but a rigid, fixed padding value from the bottom of the page to the lowest staff. Here is the test snippet without a ragged bottom, showing the default distance.

\book {
  \score {
    <<
      \new Staff <<
        \new Voice {
          s1*5 \break
          s1*5 \break
          s1*5 \break }
        \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
      >>
      \new Staff { \repeat unfold 15 { d'4 d' d' d' }
      }
    >>
  }
  \paper { ragged-last-bottom = ##f }
}
[image of music]

Setting bottom-padding yields the following result.

\book {
  \score {
    <<
      \new Staff <<
        \new Voice {
          s1*5 \break
          s1*5 \break
          \once \override
            Score.NonMusicalPaperColumn.line-break-system-details =
              #'((bottom-padding . 20))
          s1*5 \break }
        \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
      >>
      \new Staff { \repeat unfold 15 { d'4 d' d' d' } }
    >>
  }
  \paper { ragged-last-bottom = ##f }
}
[image of music]

Some points to consider:

See also

Snippets: Spacing.


LilyPond Notation Reference v2.25.32 (development-branch).