Aligning cross-staff stems when the same pitch is involved with Lilypond
I am engraving a bit for piano, where there is a chord spanning cross staff (played with the left hand). One of the pitches of the chord also appears on the right hand, and that messes up my engraving, where the stems no longer align :
There are two cross-staff stems, the left one (red) is the one I'm unhappy with, and the right one (violet) is an example of what it should look like. The image is the result of the following lilybin; the code is :
version "2.18.0"
rightHand = relative c'' {
clef "treble"
<< { g4 f4 f2} crossStaff {s4 <c f>2 <c f>4} >>
}
leftHand = relative c {
clef "bass"
stemDown {r4 a'2 a4}
}
score {
new PianoStaff
<<
new Staff = "upper" rightHand
new Staff = "lower" leftHand
>>
layout {
context {
PianoStaff
consists #Span_stem_engraver
}
}
}
Ideally, I want something that looks like :
That is, the chord must be displayed as such and appear after the right hand f4 pitch.
2 Comments
Sorted by latest first Latest Oldest Best
This answer gave hints as to how to modify my score, but even with attempted tweaks, I couldn't get what I want from it. So I set out to finding another solution, which is the following :
version "2.18.0"
rightHand = relative c'' {
clef "treble"
<< { g4 f4 f2} crossStaff {s4 <c f>2 <c f>4} >>
}
leftHand = relative c {
clef "bass"
stemDown {r4 <<a'2 new Voice{voiceOne once hideNotes a4 }>> a4}
}
score {
new PianoStaff
<<
new Staff = "upper" rightHand
new Staff = "lower" leftHand
>>
layout {
context {
PianoStaff
consists #Span_stem_engraver
}
}
}
The result is as follows :
which is what I was looking for.
Snippet available here on lilybin. The trick is to add an invisible voice.
My problem now, is that I had the idea for that from the lilypond snippet repository, and I have no idea why it works :(
I still posted an answer, because it technically answer my question. But I'd like as well to know why. Someone does ?
One solution would be to insert once override NoteColumn.force-hshift = -1.5 immediately before that first <c f>2:
But as you see, this still comes out looking a bit strange; a sight reader may well get something wrong if they're suddenly confronted with this. You may thus want to tweak some other notes.
Or, depending on the score, I may recommend putting the left hand chords all in the bass clef. You'd have ledger lines, but the notation would be far clearer.
Terms of Use Privacy policy Contact About Cancellation policy © freshhoot.com2026 All Rights reserved.