2

I often write definitions like

\begin{align*}
   f &: \mathbb{R} \to \mathbb{R}
 \\ f(0) &: 0
 \\ f(x) &= \frac{\sin x}{x}
\end{align*}

rendered version of the badly aligned version

(Yeah, I know this could also be written with a cases environment, but I'm not asking about that.)

Needless to say, the alignment is a bit of a mess here. I do want the = signs to be aligned, but it doesn't really make sense for the colon. In principle, that should just be centered by itself, and the equations below centered as well as a block, like would happen with two separate environments

separate environments

but that has its own disadvantages, including the undesired vertical space.

It's no good to just omit the alignment character

\begin{align*}
   f &: \mathbb{R} \to \mathbb{R}
 \\ f(0) &: 0
 \\ f(x) &= \frac{\sin x}{x}
\end{align*}

as that just smashes the first line entirely in the left alignment column

smashleft

Nesting environments doesn't do the trick either

\begin{align*}
   f : \mathbb{R} \to \mathbb{R}
 \\
\begin{aligned}
    f(0) &= 0
 \\ f(x) &= \frac{\sin x}{x}
\end{aligned}
\end{align*}

– this seems to result in the same as the first version, for some reason.

What's the proper way?


Related questions:

  • 1
    FTR, I actually meant to write f(0) = 1, but only noticed the discontinuity at zero in the finished question. Not that it matters for what I'm asking. – leftaroundabout Jun 08 '23 at 10:25

1 Answers1

4

You could nest an aligned environment (for rows 2 and 3) inside a gather* environment:

enter image description here

Do also note that I've inserted a typographic strut (via a \vphantom directive) in row 2 in order to separate it a bit more from rows 1 and 3. Furthermore, I would use \colon rather than : in row 1.

\documentclass{article} % or some other suitable document class
\usepackage{amsmath,amssymb}
\begin{document}

\begin{gather} f \colon \mathbb{R} \to \mathbb{R} \ \begin{aligned} f(0) &= 1 \vphantom{\frac{\sin x}{x}} \ f(x) &= \frac{\sin x}{x} \end{aligned} \end{gather}

\end{document}

Mico
  • 506,678