Jump to content

Changing the size of a staff with a music function

From LilyPond wiki

To change the size of an individual staff, you would \set the fontSize property of the Staff context, and \override the 'staff-space, and 'thickness properties of the StaffSymbol.

This snippet shows how to simplify this process by defining a music function called staffSize. It works as a macro and sets each of these three properties for you. (It can actually be used in any context that has a font size engraver, not just Staff contexts.)

If you want to resize all the staves in the file (and all the text as well), a simpler way is to use #(set-global-staff-size xx).

\version "2.24.0"

%%http://lsr.di.unimi.it/LSR/Item?id=862

staffSize = #(define-music-function (new-size) (number?)
  #{
    \set fontSize = #new-size
    \override StaffSymbol.staff-space = #(magstep new-size)
    \override StaffSymbol.thickness = #(magstep new-size)
  #})

theMusic = \relative c' { 
  a'8 a a a a \ff a a a
}

\score {
  <<
    \new Staff 
      { \theMusic }

    \new Staff \with {
      fontSize = #-3
      \override StaffSymbol.staff-space = #(magstep -3)
      \override StaffSymbol.thickness = #(magstep -3)
      } 
      { \theMusic }

    \new Staff 
    \with { \staffSize #-3 } 
      { \theMusic }
  >>
}