# Center a note in lilypond

How do I achieve this in lilypond?

This is my attempt:

{
\hide Staff.TimeSignature
d4''
\bar "||"
}


The issue is with the horizontal spacing - is there a way to hide/delete the time signature and have the note centered like above?

I'd override extra-spacing-width.

\version "2.22.2"

\layout {
\context {
\Staff
\remove Time_signature_engraver
}
\context {
\Voice
\override NoteHead.extra-spacing-width = #'(-5 . 5)
}
}

\new Staff {
d''4
\bar "||"
}


Also, about \remove: http://lilypond.org/doc/v2.23/Documentation/notation/modifying-context-plug_002dins.html.

Firstly: d4'' should be d''4, you need to place the duration (number) after the octave designation (quote/comma).

It's not clear why you want the note in the centre of the bar, so it's hard to tell what is the best way to get it to appear there.

One way would be to use invisible rests. A "spacer rest" is entered like normal rest, but with an s instead of an r. For example s4 will make an invisible quarter note (crotchet) rest.

Applying some spacer rests to your code like this:

    {
\hide Staff.TimeSignature
s4 d''4 s2 |
\bar "||"
}


will give you something similar to your first image.

However, this isn't going to work in general. This is because while using \hide Staff.TimeSignature does make the time signature invisible, it still takes up the same amount of space that it normal would. Instead you probably want to use \omit Staff.TimeSignature. This will remove the time signature and not use up any space for it.

Changing the (omitted) time signature to 3/4 and placing the note between spacer rests will get the note to appear in the middle of the bar.

    {
\time 3/4
\omit Staff.TimeSignature
s4 d''4 s4 |
\bar "||"
}

• I learned a lot from your response. My daughter is writing a music theory quiz app and lilypond looks a good fit for generating lots of examples by hooking up to python - in this case we'd generate images of notes.