LilyPond Notation Reference: 1.6.2 Modifying single staves

### 1.6.2 Modifying single staves

This section explains how to change specific attributes of one staff: for example, modifying the number of staff lines or the staff size. Methods to start and stop staves and set ossia sections are also described.

#### Staff symbol

The `\stopStaff` and `\startStaff` commands can be used to stop or (re)start the staff lines respectively, from being printed at any point witin a score.

>     \relative {
>       \stopStaff f''4 d \startStaff g, e
>       f'4 d \stopStaff g, e
>       f'4 d \startStaff g, e
>     }

#### Predefined commands

`\startStaff`, `\stopStaff`.

The lines of a staff belong to the `StaffSymbol` grob (including ledger lines) and can be modified using `StaffSymbol` properties, but these modifications must be made before the staff is (re)started.

The number of staff lines can be altered:

>     \relative {
>       f''4 d \stopStaff
>       \override Staff.StaffSymbol.line-count = #2
>       \startStaff g, e |

>       f'4 d \stopStaff
>       \revert Staff.StaffSymbol.line-count
>       \startStaff g, e |
>     }

The position of each staff line can also be altered. A list of numbers sets each line’s position. `0` corresponds to the normal center line, and the normal line positions are `(-4 -2 0 2 4)`. A single staff line is printed for every value entered so that the number of staff lines, as well as their position, can be changed with a single override.

>     \relative {
>       f''4 d \stopStaff
>       \override Staff.StaffSymbol.line-positions = #'(1 3 5 -1 -3)
>       \startStaff g, e |
>       f'4 d \stopStaff
>       \override Staff.StaffSymbol.line-positions = #'(8 6.5 -6 -8 -0.5)
>       \startStaff g, e |
>     }

To preserve typical stem directions (in the bottom half of the staff stems point up, in the top half they point down), align the center line (or space) of the customized staff with the position of the normal center line (0). The clef position and the position of middle C may need to be adjusted accordingly to fit the new lines. See Clef.

Staff line thickness can be altered. Ledger lines and note stems, by default, are also affected.

>     \new Staff \with {
>       \override StaffSymbol.thickness = #3
>     } \relative {
>       f''4 d g, e
>     }

It is also possible to set ledger line thickness independently of staff lines.

>     \new Staff \with {
>       \override StaffSymbol.thickness = #2
>       \override StaffSymbol.ledger-line-thickness = #'(0.5 . 0.4)
>     } \relative {
>       f'''4 a, a,, f
>     }

The first value is multiplied by the staff line thickness, the second by the staff space and then the two values are added together to give the new thickness of the ledger line.

The vertical positions of ledger lines can be altered,

>     \new Staff \with {
>       \override StaffSymbol.ledger-positions = #'(-3 -2 -1 2 5 6)
>     } \relative {
>       f'''4 a, a,, f
>     }

Additional ledger lines can be made to appear above or below note heads depending on the current position relative to other note heads that also have their own ledger lines.

>     \new Staff \with {
>       \override StaffSymbol.ledger-extra = #4
>     } \relative {
>       f'''4 a, d, f,
>     }

Ledger lines can also be made to appear inside the staff where custom staff lines are required. The example shows the default position of ledger lines when the explicit `ledger-position` is and is not set. The `\stopStaff` is needed in the example to revert the `\override` for the whole `StaffSymbol`.

>     \relative d' {
>       \override Staff.StaffSymbol.line-positions = #'(-8 0 2 4)
>       d4 e f g
>       \stopStaff
>       \startStaff
>       \override Staff.StaffSymbol.ledger-positions = #'(-8 -6 (-4 -2) 0)
>       d4 e f g
>     }

The distance between staff lines can be altered. This affects ledger line spacing as well.

>     \new Staff \with {
>       \override StaffSymbol.staff-space = #1.5
>     } \relative {
>       f'''4 d, g, e,
>     }

#### Selected Snippets

Making some staff lines thicker than the others

For educational purposes, a staff line can be thickened (e.g., the middle line, or to emphasize the line of the G clef). This can be achieved by adding extra lines very close to the line that should be emphasized, using the `line-positions` property of the `StaffSymbol` object.

>     {
>       \override Staff.StaffSymbol.line-positions =
>         #'(-4 -2 -0.2 0 0.2 2 4)
>       d'4 e' f' g'
>     }

#### See also

Music Glossary: line, ledger line, staff.

Notation Reference: Clef.

Snippets: Staff notation.

Internals Reference: StaffSymbol, staff-symbol-interface.

#### Ossia staves

Ossia staves can be set by creating a new simultaneous staff in the appropriate location:

>     \new Staff \relative {
>       c''4 b d c
>       <<
>         { c4 b d c }
>         \new Staff { e4 d f e }
>       >>
>       c4 b c2
>     }

However, the above example is not what is usually desired. To create ossia staves that are above the original staff, have no time signature or clef, and have a smaller font size, tweaks must be used. The Learning Manual describes a specific technique to achieve this goal, beginning with Nesting music expressions.

The following example uses the `alignAboveContext` property to align the ossia staff. This method is most appropriate when only a few ossia staves are needed.

>     \new Staff = "main" \relative {
>       c''4 b d c
>       <<
>         { c4 b d c }

>         \new Staff \with {
>           \remove "Time_signature_engraver"
>           alignAboveContext = "main"
>           \magnifyStaff #2/3
>           firstClef = ##f
>         }
>         { e4 d f e }
>       >>
>       c4 b c2
>     }

If many isolated ossia staves are needed, creating an empty `Staff` context with a specific context id may be more appropriate; the ossia staves may then be created by calling this context and using `\startStaff` and `\stopStaff` at the desired locations. The benefits of this method are more apparent if the piece is longer than the following example.

>     <<
>       \new Staff = "ossia" \with {
>         \remove "Time_signature_engraver"
>         \hide Clef
>         \magnifyStaff #2/3
>       }
>       { \stopStaff s1*6 }

>       \new Staff \relative {
>         c'4 b c2
>         <<
>           { e4 f e2 }
>           \context Staff = "ossia" {
>             \startStaff e4 g8 f e2 \stopStaff
>           }
>         >>
>         g4 a g2 \break
>         c4 b c2
>         <<
>           { g4 a g2 }
>           \context Staff = "ossia" {
>             \startStaff g4 e8 f g2 \stopStaff
>           }
>         >>
>         e4 d c2
>       }
>     >>

Using the `\RemoveAllEmptyStaves` command to create ossia staves may be used as an alternative. This method is most convenient when ossia staves occur immediately following a line break. For more information about `\RemoveAllEmptyStaves`, see Hiding staves.

>     <<
>       \new Staff = "ossia" \with {
>         \remove "Time_signature_engraver"
>         \hide Clef
>         \magnifyStaff #2/3
>         \RemoveAllEmptyStaves
>       } \relative {
>         R1*3
>         c''4 e8 d c2
>       }
>       \new Staff \relative {
>         c'4 b c2
>         e4 f e2
>         g4 a g2 \break
>         c4 b c2
>         g4 a g2
>         e4 d c2
>       }
>     >>

#### Selected Snippets

Vertically aligning ossias and lyrics

This snippet demonstrates the use of the context properties `alignBelowContext` and `alignAboveContext` to control the positioning of lyrics and ossias.

>     \paper {
>       ragged-right = ##t
>     }

>     \relative c' <<
>       \new Staff = "1" { c4 c s2 }
>       \new Staff = "2" { c4 c s2 }
>       \new Staff = "3" { c4 c s2 }
>       { \skip 2
>         <<
>           \lyrics {
>             \set alignBelowContext = #"1"
>             lyrics4 below
>           }
>           \new Staff \with {
>             alignAboveContext = #"3"
>             fontSize = #-2
>             \override StaffSymbol.staff-space = #(magstep -2)
>             \remove "Time_signature_engraver"
>           } {
>             \tuplet 6/4 {
>               \override TextScript.padding = #3
>               c8[^"ossia above" d e d e f]
>             }
>           }
>         >>
>       }
>     >>

#### See also

Music Glossary: ossia, staff, Frenched staff.

Learning Manual: Nesting music expressions, Size of objects, Length and thickness of objects.

Notation Reference: Hiding staves.

Snippets: Staff notation.

Internals Reference: StaffSymbol.

#### Hiding staves

Staff lines can be hidden by removing the `Staff_symbol_engraver` from the `Staff` context. As an alternative, `\stopStaff` may be used.

>     \new Staff \with {
>       \remove "Staff_symbol_engraver"
>     }
>     \relative { a''8 f e16 d c b a2 }

Empty staves can be hidden (for a so-called ‘Frenched Score’) by applying the `\RemoveEmptyStaves` command on a context, which can be done globally (in a `\layout` block) as well as for specific staves only (in a `\with` block). This command removes all empty staves in a score except for those in the first system. If you want those in the first system to be hidden also, use `\RemoveAllEmptyStaves`.

>     \layout {
>       \context {
>         \Staff
>         \RemoveEmptyStaves
>       }
>     }

>     \relative <<
>       \new Staff {
>         e'4 f g a \break
>         b1 \break
>         a4 b c2
>       }
>       \new Staff {
>         c,4 d e f \break
>         R1 \break
>         f4 g c,2
>       }
>     >>

A staff is considered empty when it contains only multi-measure rests, rests, skips, or a combination of these elements. All other musical objects (that cause a staff not to be considered as empty) are listed in the `keepAliveInterfaces` context property, as initially set in the ‘`ly/engraver-init.ly`’ file.

`\RemoveEmptyStaves` and `\RemoveAllEmptyStaves` are both predefined shortcuts that set such properties as `remove-empty` and `remove-first` for the `VerticalAxisGroup` object, as explained in Context modification identifiers.

The `Keep_alive_together_engraver` allows groups of staves to only be removed together and not individually. By default, it is part of the `PianoStaff` context: a piano part will only be hidden when both of its staves are empty. Similarly, a common engraving practice in orchestral scores is to remove empty groups of staves rather than individual staves; that can be achieved by adding the `Keep_alive_together_engraver` to the relevant staff-grouping context, as explained Modifying context plug-ins (see Grouping staves for the context names).

>     \layout {
>       \context {
>         \StaffGroup
>         \RemoveEmptyStaves
>         \consists "Keep_alive_together_engraver"
>       }
>     }

In the following example, staves devoted to wind instruments are removed in the second system; however, the double bass is not, because it is part of the larger group of fretted strings, which is playing.

The `Keep_alive_together_engraver` internally uses the `remove-layer` property of a staff’s `VerticalAxisGroup` to decide whether to print it or not when it is considered empty. That property may also be set directly, in which case it acts as a priority index: values closest to zero take precedence over higher numbers, and thus staves whose `remove-layer` is higher will be masked in favor of staves of a lower number.

This is particularly useful for ‘divisi’ staves, where some individual parts (see Writing parts) occasionally need to be expanded to more than one staff. In the following example, two parts are routed to three staves; however, all three staves are never printed at the same time:

- in the first systems, only a single one of them is shown, as the `keepAliveInterfaces` property has been set to an empty list – therefore the other two staves are considered empty and thus hidden, regardless of what they may contain;
- when that property gets unset (and thus reverts to its default setting), it is no longer preventing the two other staves from being printed; however, as their `remove-layer` setting is lower than the single staff’s, these two staves are now printed in its place.

Such substitutions are applied not just to notes, chords and other musical events that occur immediately after the new setting, but to the whole system where it takes place.

    \layout {
      short-indent = 2\cm
      indent = 3\cm
      \context {
        \Staff
        keepAliveInterfaces = #'()
      }
    }

    violI = {
      \repeat unfold 24 { d'4 }
      \once \unset Staff.keepAliveInterfaces
      <d' g''>2
      \repeat unfold 14 { d'4 }
      \bar "|."
    }

    violII = {
      \repeat unfold 24 { g4 }
      <g d'>2
      \repeat unfold 14 { g4 }
      \bar "|."
    }

    \new StaffGroup \with { \consists "Keep_alive_together_engraver" } <<
      \new Staff \with {
        instrumentName = "Violins"
        shortInstrumentName = "V I & II"
        \override VerticalAxisGroup.remove-layer = 2
      } <<  \violI \\ \violII  >>
      \new Staff \with {
        instrumentName = "Violin I"
        shortInstrumentName = "V I"
        \RemoveAllEmptyStaves
        \override VerticalAxisGroup.remove-layer = 1
      } \violI
      \new Staff \with {
        instrumentName = "Violin II"
        shortInstrumentName = "V II"
        \RemoveAllEmptyStaves
        \override VerticalAxisGroup.remove-layer = 1
      } \violII
    >>

`\RemoveAllEmptyStaves` can also be used to create ossia sections for a staff. For details, see Ossia staves.

#### Predefined commands

`\RemoveEmptyStaves`, `\RemoveAllEmptyStaves`.

#### See also

Music Glossary: Frenched staff.

Learning Manual: Visibility and color of objects.

Notation Reference: Changing context default settings, Staff symbol, Ossia staves, Hidden notes, Invisible rests, Visibility of objects, Context modification identifiers, Grouping staves, Modifying context plug-ins.

Installed Files: ‘`ly/engraver-init.ly`’.

Snippets: Staff notation.

Internals Reference: ChordNames, FiguredBass, Lyrics, Staff, VerticalAxisGroup, Staff_symbol_engraver, Axis_group_engraver, Keep_alive_together_engraver.

#### Known issues and warnings

Removing `Staff_symbol_engraver` also hides bar lines. If bar line visibility is forced, formatting errors may occur. In this case, use the following overrides instead of removing the engraver:

>     \omit StaffSymbol
>     \override NoteHead.no-ledgers = ##t

For the Known issues and warnings associated with `\RemoveEmptyStaves` see Changing context default settings.

#### LilyPond — Notation Reference v2.22.2 (stable-branch).