2

I am trying to display chord diagrams with LilyPond to the side of the chord names.

By default, LilyPond renders the diagram below the chord name like so:
chord name directly above fretboard diagram

but I want them to be side by side like so:
chord name on the left of fretboard diagram.

How can I accomplish this with LilyPond?

So far I am able to get the following output, but the diagrams are too far from the staff: enter image description here

The ideal state would look something like this. The diagrams and chord names stick close together and also close to the staff below: enter image description here

1 Answer 1

2

You can override the alignment direction of the fretboard diagrams with:
\override FretBoard.align-dir = #LEFT

And you can override the horizontal and vertical offsets with:
\override FretBoard.X-offset = #5 &
\override FretBoard.Y-offset = #5

To get the chord names and fretboard diagrams to sit to the top of the staff/tablature you will also need to use:
\override VerticalAxisGroup.staff-affinity = #DOWN

All together you'll get something like this:

\version "2.24.0"

\include "predefined-guitar-fretboards.ly"

theChords = {
    \set chordChanges = ##t
    \chordmode {
        a1:m | c | g | g | \break
        e | e | a:m | c |
    }
}

\score {
    <<
        \new FretBoards {
            \override VerticalAxisGroup.staff-affinity = #DOWN
            \override FretBoard.align-dir = #LEFT
            \override FretBoard.X-offset = #5
            \override FretBoard.Y-offset = #5
            
            \theChords
        }
        \new ChordNames {
            \theChords
        }
        \new TabStaff {
            \predefinedFretboardsOn
            \theChords
        }
    >>
}

(You might need to adjust the horizontal offset value depending on how many measures per line you have.)

Tablature with chords, chord names above, and fretboard diagrams above and offset to the right.

9
  • Thank you! This is close to what I want. But when I try to move the chord name lower and closer to the diagram (similar to the shared image in my question), the diagram keeps moving up, further away from the staff and I end up having similar amount of vertical space, which I was trying to avoid. Any idea how to avoid this effect? I tried to use \override FretBoard.align-dir = #LEFT \override FretBoard.X-offset = #6 \override FretBoard.Y-offset = #6
    – JAV
    Oct 8, 2023 at 18:43
  • @JAV I've added a Y-offset to my answer, but I'm not sure if this is quite right yet. Are you saying that you want the chord names and the fretboard diagrams to be even closer to the tablature? Oct 9, 2023 at 1:59
  • Thank youm this is awesome! :) When I try out the code from your example, my result looks a bit worse - the diagrams are a bit too far and the chord names too. I updated my answer to display what I currently get. I am on version 2.20.0. Maybe that could play some role?
    – JAV
    Oct 9, 2023 at 11:30
  • @JAV Thanks for the image, I found what was going wrong. I've added \override VerticalAxisGroup.staff-affinity = #DOWN to the other overrides, and I think that solves the problem. Oct 9, 2023 at 12:46
  • 1
    @JAV If you want to change the chord names horizontal position, use something like: \override ChordName.X-offset = #-4, inside the CordNames block. (Then you might want to remove the fretboard's X-offset.) Oct 9, 2023 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.