Paper and layout

Spacing issues


Aligning and centering instrument names

The horizontal alignment of instrument names is tweaked by changing the Staff.InstrumentName.self-alignment-X property. The \layout variables indent and short-indent define the space in which the instrument names are aligned before the first and the following systems, respectively.

\paper { left-margin = 3\cm }

\score {
  \new StaffGroup <<

    \new Staff \with {
      \override InstrumentName.self-alignment-X = #LEFT
      instrumentName = \markup \left-column {
        "Left aligned"
        "instrument name"
        }
        shortInstrumentName = "Left"
      }

      {  c''1 \break c''1 }

    \new Staff \with {
      \override InstrumentName.self-alignment-X = #CENTER
      instrumentName = \markup \center-column {
        Centered
        "instrument name"
        }
      shortInstrumentName = "Centered"
    }

    { g'1 g'1}

    \new Staff \with {
      \override InstrumentName.self-alignment-X = #RIGHT
      instrumentName = \markup \right-column {
        "Right aligned"
        "instrument name"
      }
      shortInstrumentName = "Right"
    }

    { e'1 e'1 }

  >>

  \layout {
    ragged-right = ##t
    indent = 4\cm
    short-indent = 2\cm
  }
}

[image of music]


Arranging separate lyrics on a single line

Sometimes you may want to put lyrics for different performers on a single line: where there is rapidly alternating text, for example. This snippet shows how this can be done with \override VerticalAxisGroup.nonstaff-nonstaff-spacing.minimum-distance = ##f.

\layout {
  \context {
    \Lyrics
    \override VerticalAxisGroup.nonstaff-nonstaff-spacing.minimum-distance = ##f
  }
}

aliceSings = \markup { \smallCaps "Alice" }
eveSings = \markup { \smallCaps "Eve" }

<<
  \new Staff <<
    \new Voice = "alice" {
      f'4^\aliceSings g' r2 |
      s1 |
      f'4^\aliceSings g' r2 |
      s1 | \break
      % ...

      \voiceOne
      s2 a'8^\aliceSings a' b'4 |
      \oneVoice
      g'1
    }
    \new Voice = "eve" {
      s1 |
      a'2^\eveSings g' |
      s1 |
      a'2^\eveSings g'
      % ...

      \voiceTwo
      f'4^\eveSings a'8 g' f'4 e' |
      \oneVoice
      s1
    }
  >>
  \new Lyrics \lyricsto "alice" {
    may -- be
    sec -- ond
    % ...
    Shut up, you fool!
  }
  \new Lyrics \lyricsto "eve" {
    that the
    words are
    % ...
    …and then I was like–
  }
>>

[image of music]


Book parts

\bookpart can be used to split a book into several parts. Each part last page can be affected by ragged-last-bottom. Header and footer markups can detect a part last page, and make the difference with the book last page.

#(set-default-paper-size "a6")

\book {
  %% book paper, which is inherited by all children bookparts
  \paper {
    ragged-last-bottom = ##t
    %% Page footer: add a different part-tagline at part last page
    oddFooterMarkup = \markup {
      \column {
        \fill-line {
          %% Copyright header field only on book first page.
          \if \on-first-page \fromproperty #'header:copyright
        }
        \fill-line {
          %% Part tagline header field only on each part last page.
          \if \on-last-page-of-part \fromproperty #'header:parttagline
        }
        \fill-line {
          %% Tagline header field only on book last page.
          \if \on-last-page \fromproperty #'header:tagline
        }
      }
    }
  }

  %% book header, which is inherited by the first bookpart
  \header {
    title = "Book title"
    copyright = "Copyright line on book first page"
    parttagline = "Part tagline"
    tagline = "Book tagline"
  }

  \bookpart {
    %% a different page breaking function may be used on each part
    \paper { page-breaking = #ly:minimal-breaking }
    \header { subtitle = "First part" }
    \markup { The first book part }
    \markup { a page break }
    \pageBreak
    \markup { first part last page }
    \markup \wordwrap { with ragged-last-bottom (see the space below this text) }
  }

  \bookpart {
    \header { subtitle = "Second part" }
    { c'4 }
  }

}

[image of music]


Changing the staff size

Though the simplest way to resize staves is to use #(set-global-staff-size xx), an individual staff’s size can be changed by scaling the properties 'staff-space and fontSize.

<<
  \new Staff {
    \relative c'' {
      \dynamicDown
      c8\ff c c c c c c c
    }
  }
  \new Staff \with {
    fontSize = #-3
    \override StaffSymbol.staff-space = #(magstep -3)
  } {
    \clef bass
    c8 c c c c\f c c c
  }
>>

[image of music]


Clip systems

This code shows how to clip (extract) snippets from a full score.

This file needs to be run separately with -dclip-systems; the snippets page may not adequately show the results. The result will be files named ‘base-from-start-to-end[-count].eps’.

If system starts and ends are included, they include extents of the System grob, e.g., instrument names.

Grace notes at the end point of the region are not included.

Regions can span multiple systems. In this case, multiple EPS files are generated.

#(ly:set-option 'clip-systems)
#(define output-suffix "1")

origScore = \score {
  \relative c' {
    \new Staff \with { instrumentName = "Instrument" }
    c1
    d1
    \grace c16 e1
    \key d \major
    f1 \break
    \clef bass
    g,1
    fis1
  }
}

\book {
  \score {
    \origScore
    \layout {
      % Each clip-region is a (START . END) pair
      % where both are rhythmic-locations.

      % (make-rhythmic-locations BAR-NUMBER NUM DEN)
      % means NUM/DEN whole-notes into bar numbered BAR-NUMBER

      clip-regions = #(list
      (cons
       (make-rhythmic-location 2 0 1)
       (make-rhythmic-location 4 0 1))

      (cons
       (make-rhythmic-location 0 0 1)
       (make-rhythmic-location 4 0 1))

      (cons
       (make-rhythmic-location 0 0 1)
       (make-rhythmic-location 6 0 1))
      )
    }
  }
}

#(ly:set-option 'clip-systems #f)
#(define output-suffix #f)

\book {
  \score { \origScore }
  \markup { \bold \fontsize #6 clips }
  \score {
    \lyrics {
      \markup { from-2.0.1-to-4.0.1-clip.eps }
      \markup {
        \epsfile #X #30.0 #(format #f "~a-1-from-2.0.1-to-4.0.1-clip.eps"
                            (ly:parser-output-name)) }
    }
  }
}

[image of music]


Creating blank staves

To create blank staves, generate empty measures then remove the Bar_number_engraver from the Score context, and the Time_signature_engraver, Clef_engraver and Bar_engraver from the Staff context.

#(set-global-staff-size 20)

\score {
  {
    \repeat unfold 12 { s1 \break }
  }
  \layout {
    indent = 0\in
    \context {
      \Staff
      \remove "Time_signature_engraver"
      \remove "Clef_engraver"
      \remove "Bar_engraver"
    }
    \context {
      \Score
      \remove "Bar_number_engraver"
    }
  }
}

% uncomment these lines for "letter" size
%{
\paper {
  #(set-paper-size "letter")
  ragged-last-bottom = ##f
  line-width = 7.5\in
  left-margin = 0.5\in
  bottom-margin = 0.25\in
  top-margin = 0.25\in
}
%}

% uncomment these lines for "A4" size
%{
\paper {
  #(set-paper-size "a4")
  ragged-last-bottom = ##f
  line-width = 180
  left-margin = 15
  bottom-margin = 10
  top-margin = 10
}
%}

[image of music]


Demonstrating all headers

All header fields with special meanings.

\header {
  copyright = "copyright"
  title = "title"
  subtitle = "subtitle"
  composer = "composer"
  arranger = "arranger"
  instrument = "instrument"
  meter = "meter"
  opus = "opus"
  piece = "piece"
  poet = "poet"
  texidoc = "All header fields with special meanings."
  copyright = "public domain"
  enteredby = "jcn"
  source = "urtext"
}

\layout {
  ragged-right = ##f
}

\score {
  \relative c'' { c1 | c | c | c }
}

\score {
   \relative c'' { c1 | c | c | c }
   \header {
     title = "localtitle"
     subtitle = "localsubtitle"
     composer = "localcomposer"
     arranger = "localarranger"
     instrument = "localinstrument"
     metre = "localmetre"
     opus = "localopus"
     piece = "localpiece"
     poet = "localpoet"
     copyright = "localcopyright"
   }
}

[image of music]


Setting system separators

System separators can be inserted between systems. Any markup can be used, but \slashSeparator has been provided as a sensible default.

\paper {
  system-separator-markup = \slashSeparator
  line-width = 120
}

notes = \relative c' {
  c1 | c \break
  c1 | c \break
  c1 | c
}

\book {
  \score {
    \new GrandStaff <<
      \new Staff \notes
      \new Staff \notes
    >>
  }
}

[image of music]


Table of contents

A table of contents is included using \markuplist \table-of-contents. The TOC items are added with the \tocItem command.

#(set-default-paper-size "a6")

\book {
  \markuplist \table-of-contents
  \pageBreak
  \tocItem \markup { The first score }
  \score {
    {
      c'1 \pageBreak
      \mark \default \tocItem \markup { Mark A }
      d'1
    }
  }
  \pageBreak
  \tocItem \markup { The second score }
  \score {
    { e'1 }
    \header { piece = "Second score" }
  }
}

[image of music]


Vertical aligned StaffGroups without connecting SystemStartBar

This snippet shows how to achieve vertically aligned StaffGroups with a SystemStartBar for each StaffGroup, but without connecting them.

#(set-global-staff-size 18)

\paper {
  indent = 0
  ragged-right = ##f
  print-all-headers = ##t
}

\layout {
  \context {
    \StaffGroup
    \consists Text_mark_engraver
    \consists Staff_collecting_engraver
    systemStartDelimiterHierarchy =
      #'(SystemStartBrace (SystemStartBracket a b))
  }

  \context {
    \Score
    \remove Text_mark_engraver
    \remove Staff_collecting_engraver
    \override SystemStartBrace.style = #'bar-line
    \omit SystemStartBar
    \override SystemStartBrace.padding = #-0.1
    \override SystemStartBrace.thickness = #1.6
    \override StaffGrouper.staffgroup-staff-spacing.basic-distance = #15
  }
}

%%%% EXAMPLE

txt =
\lyricmode {
  Wer4 nur den lie -- ben Gott läßt wal2 -- ten4
  und4 hof -- fet auf ihn al -- le Zeit2.
}

% First StaffGroup "exercise"

eI =
\relative c' {
        \textMark \markup {
                \bold Teacher:
                This is a simple setting of the choral. Please improve it.
                }
        \key a \minor
        \time 4/4
        \voiceOne

        \partial 4
        e4
        a b c b
        a b gis2
        e4\fermata g! g f
        e a a gis
        a2.\fermata
        \bar ":|."
}

eII =
\relative c' {
        \key a \minor
        \time 4/4
        \voiceTwo
        \partial 4
        c4
        e e e gis
        a f e2
        b4 b d d
        c c d d
        c2.
        \bar ":|."
}

eIII =
\relative c' {
        \key a \minor
        \time 4/4
        \clef bass
        \voiceOne

        \partial 4
        a4
        c b a b
        c d b2
        gis4 g g b
        c a f e
        e2.
}

eIV =
\relative c' {
        \key a \minor
        \time 4/4
        \clef bass
        \voiceTwo

        \partial 4
        a,4
        a' gis a e
        a, d e2
        e,4\fermata e' b g
        c f d e
        a,2.\fermata
        \bar ":|."
}

exercise =
\new StaffGroup = "exercise"
<<

  \new Staff
    <<
      \new Voice \eI
      \new Voice \eII
    >>

  \new Lyrics \txt

  \new Staff
    <<
      \new Voice \eIII
      \new Voice \eIV
    >>
>>

% Second StaffGroup "simple Bach"

sbI =
\relative c' {
        \textMark \markup { \bold" Pupil:" Here's my version! }
        \key a \minor
        \time 4/4
        \voiceOne

        \partial 4
        e4
        a b c b
        a b gis2
        e4\fermata g! g f
        e a a gis
        a2.\fermata
        \bar ":|."
}

sbII =
\relative c' {
        \key a \minor
        \time 4/4
        \voiceTwo
        \partial 4
        c8 d
        e4 e e8 f g4
        f f e2
        b4 b8 c d4 d
        e8 d c4 b8 c d4
        c2.
        \bar ":|."
}

sbIII =
\relative c' {
        \key a \minor
        \time 4/4
        \clef bass
        \voiceOne

        \partial 4
        a8 b
        c4 b a b8 c
        d4 d8 c b2
        gis4 g g8 a b4
        b a8 g f4 e
        e2.
}

sbIV =
\relative c' {
        \key a \minor
        \time 4/4
        \clef bass
        \voiceTwo

        \partial 4
        a,4
        a' gis a e
        f8 e d4 e2
        e,4\fermata e' b a8 g
        c4 f8 e d4 e
        a,2.\fermata
        \bar ":|."
}

simpleBach =
\new StaffGroup = "simple Bach"
<<

  \new Staff
    <<
      \new Voice \sbI
      \new Voice \sbII
    >>

  \new Lyrics \txt

  \new Staff
    <<
      \new Voice \sbIII
      \new Voice \sbIV
    >>
>>

% Third StaffGroup "chromatic Bach"

cbI =
\relative c' {
        \textMark \markup {
          \bold "Teacher:"
          \column {
            "Well, you simply copied and transposed a version of J.S.Bach."
            "Do you know this one?"
          }
        }
        \key a \minor
        \time 4/4
        \voiceOne

        \partial 4
        e4
        a b c b
        a b gis4. fis8
        e4\fermata g! g f
        e a a8 b gis4
        a2.\fermata
        \bar ":|."
}

cbII =
\relative c' {
        \key a \minor
        \time 4/4
        \voiceTwo
        \partial 4
        c8 d
        e4 e e8 fis gis4
        a8 g! f!4 e2
        b4 e e d
        d8[ cis] d dis e fis e4
        e2.
        \bar ":|."
}

cbIII =
\relative c' {
        \key a \minor
        \time 4/4
        \clef bass
        \voiceOne

        \partial 4
        a8 b
        c[ b] a gis8 a4 d,
        e8[ e'] d c b4. a8
        gis4 b c d8 c
        b[ a] a b c b b c16 d
        c2.
}

cbIV =
\relative c' {
        \key a \minor
        \time 4/4
        \clef bass
        \voiceTwo

        \partial 4
        a4
        c, e a, b
        c d e2
        e4\fermata e a b8 c
        gis[ g] fis f e dis e4
        a,2.\fermata
        \bar ":|."
}

chromaticBach =
\new StaffGroup = "chromatic Bach"
<<

  \new Staff
    <<
      \new Voice \cbI
      \new Voice \cbII
    >>

  \new Lyrics \txt

  \new Staff
    <<
      \new Voice \cbIII
      \new Voice \cbIV
    >>
>>


% Score

\score {
        <<
        \exercise
        \simpleBach
        \chromaticBach
        >>
        \header {
                title = \markup
                           \column {
                             \combine \null \vspace #1
                             "Exercise: Improve the given choral"
                             " "
                            }
        }
        \layout {
                \context {
                        \Lyrics
                        \override LyricText.X-offset = #-1
                }
        }
}

[image of music]


LilyPond — Snippets v2.23.82 (development-branch).