Remove vertical space added by #align()

I have a bullet list, with some parts of the bullet list that need to be center-aligned. However, when I use #align(center) it also adds a vertical space above the content, making the bullet-spacing look bad.

How do I prevent #align() from adding the vertical space above that line?

MWE:

With #align(), adds ugly vertical spacing:

- We can etch through the SiO2 layer in \ 
  #align(center)[250~nm~x~(1~min/500~nm)~=
  0.5~min~=~30~seconds]
- We would add a 30% overetch like so: \ 
  #align(center)[30~sec~x~(1.30)~≈~40~sec total etch time]

Compare to without the #align() function (but left-aligned text looks ugly):

- We can etch through the SiO2 layer in \ 
  250~nm~x~(1~min/500~nm)~=
  0.5~min~=~30~seconds
- We would add a 30% overetch like so: \ 
  30~sec~x~(1.30)~≈~40~sec total etch time

(Similar to this post, but it didn’t seem to have an answer as far as I can tell.)

(I could alternatively indent those lines… FYI math notation was annoying to code up due to the use of words in the equations. However, answering the base question about removing vertical space would hopefully be helpful for other users, not just my text.)

Thanks!

Using align starts a new paragraph, see Align Function – Typst Documentation

This means that the spacing you see is controlled by the spacing between two paragraphs (par.spacing), which we can adjust to be equal to the spacing between lines inside of a paragraph (par.leading):

#show list: it => context {
  set par(spacing: par.leading)
  it
} 

Alternatively, we could avoid using paragraphs entirely by adding spacing around the alignable item:

#show list.item: it => context {
  show align: al => h(1fr) + al.body + h(1fr)
  it
}

And if we wanted to remove the extra spacing, we could wrap it in a box:

#show list: it => context {
  let list-width = measure(it).width
  show align: al => box(
    width: list-width, 
    h(1fr) + al.body + h(1fr)
  )
  it
}

2 Likes

Nicely done! Thank you very much.