[Tex/LaTex] Control Spacing and Alignment in align environment

alignamsmathmath-mode

I have an align-environment and basically want all the Z's and all the signs (+-) left-aligned + all centered + the smallest possible/sane gap in between + numbering + labels (if possible):

Want and have

Produced by the code:

I have:
\begin{align}
    & Z_i(f) = R_i(f) & + i \cdot X_i(f) \label{eq:Zi} & \\
    & Z_R(f)=R & +i\cdot 0 \label{eq:ZR} & \\
    & Z_L(f)=0 & +i \cdot \underbrace{ 2 \pi f L }_{X_L} \label{eq:ZL} & \\
    & Z_C(f)=0 & -i \cdot \underbrace{ \frac{1}{2 \pi f \cdot C} }_{X_C} & \label{eq:ZC}
\end{align}

I want:
\begin{align}
    & Z_i(f) = R_i(f) & & + i \cdot X_i(f) \label{eq:Zi} & \\
    & Z_R(f)=R & & +i\cdot 0 \label{eq:ZR} & \\
    & Z_L(f)=0 & & +i \cdot \underbrace{ 2 \pi f L }_{X_L} \label{eq:ZL} & \\
    \phantom{\hspace{5cm}} & Z_C(f)=0 & & -i \cdot \underbrace{ \frac{1}{2 \pi f \cdot C} }_{X_C} &  \label{eq:ZC} \phantom{\hspace{5cm}}
\end{align}

Now I feel that the second code is not very nice (e.g. it will need adjustment of the phantom-spacing each time something is changed). Also the number of the last formula is at the wrong place.

Anyone have any suggestions?

Best Answer

You want alignat:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

You want
\begin{alignat}{2}
Z_i(f) &= R_i(f) && + i \cdot X_i(f) \label{eq:Zi} \\
Z_R(f) &= R      && + i \cdot 0 \label{eq:ZR} \\
Z_L(f) &= 0      && + i \cdot \underbrace{ 2 \pi f L }_{X_L} \label{eq:ZL} \\
Z_C(f) &= 0      && - i \cdot \underbrace{ \frac{1}{2 \pi f \cdot C} }_{X_C} \label{eq:ZC}
\end{alignat}

\end{document}

enter image description here

Related Question