# Control Spacing and Alignment in align environment

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):

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?

• You want alignat Aug 6, 2015 at 16:38
• the reason the number on the last formula is on a new line is that the additional 10cm of width you inserted makes the line too long, and that forces the number to a separate line. also, the purpose of \phantom is to hide visible output. since \hspace doesn't produce anything "printed", the \phantom isn't necessary. Aug 6, 2015 at 16:50

## 1 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}


• Thank you! Why would you prefer using &= instead in front of Z ? Aug 6, 2015 at 16:49
• @3244611user -- it's more "traditional" to align the signs of relation than the beginning of consecutive formulas. Aug 6, 2015 at 16:51
• I think I've been looking for this for 3 years now, but I had never come across the alignat environment, much appreciated! Oct 4, 2020 at 17:11
• Well, if you're that Daneel Olivaw, three years are nothing. ;-) Oct 4, 2020 at 18:53