Jump to content

Consistently left-aligned bar numbers (obsolete in 2.23): Difference between revisions

From LilyPond wiki
m Replace version="2.24.0" with version="2.24" now that the LilyWiki extension supports auto-selecting the latest release in a stable series
Fix layout
Line 3: Line 3:
The snippet solves this by keeping the first bar number right-aligned that follows a line break.
The snippet solves this by keeping the first bar number right-aligned that follows a line break.


<lilypond version="2.24" full>
<lilypond version="2.24">
consistentlyLeftAlignedBarNumbers = {
consistentlyLeftAlignedBarNumbers = {
   \override Score.BarNumber.break-visibility = #end-of-line-invisible
   \override Score.BarNumber.break-visibility = #end-of-line-invisible
Line 33: Line 33:
   }
   }
>>
>>
\layout {
  indent = #0
  ragged-right = ##t
  ragged-last = ##t
}
\paper { tagline = ##f }
</lilypond>
</lilypond>


[[Category:Rhythms]]
[[Category:Rhythms]]
[[Category:Included in the official documentation]]
[[Category:Included in the official documentation]]

Revision as of 19:20, 16 November 2025

When left-aligning bar numbers, overlapping problems may occur with staff brackets.

The snippet solves this by keeping the first bar number right-aligned that follows a line break.

\version "2.24"

consistentlyLeftAlignedBarNumbers = {
  \override Score.BarNumber.break-visibility = #end-of-line-invisible
  \override Score.BarNumber.self-alignment-X =
    #(lambda (grob)
       (let ((break-dir (ly:item-break-dir grob)))
         (if (= break-dir RIGHT) RIGHT LEFT)))
}

\new ChoirStaff <<
  \new Staff {
    \relative c' {
      \set Score.barNumberVisibility = #(every-nth-bar-number-visible 3)
      \bar ""
      \consistentlyLeftAlignedBarNumbers

      \set Score.currentBarNumber = #112
      \repeat unfold 8 { R1 }
      \break
      \repeat unfold 9 { R1 }
      \break
      \repeat unfold 7 { R1 }
    }
  }
  \new Staff {
    \relative c' {
      \repeat unfold 24 { R1 }
    }
  }
>>