3

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?

  • You want alignat – egreg Aug 6 '15 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. – barbara beeton Aug 6 '15 at 16:50
4

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

  • Thank you! Why would you prefer using &= instead in front of Z ? – 3244611user Aug 6 '15 at 16:49
  • 1
    @3244611user -- it's more "traditional" to align the signs of relation than the beginning of consecutive formulas. – barbara beeton Aug 6 '15 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.