4

This question already has an answer here:

Just a quick question regarding aligning equations in LaTeX. Basically, this is a snippet of my source code:

\begin{align*}
  dU&=\partial Q - \partial W \\
  \partial Q &= dU + \partial W
\end{align*}
Since $U_E$ was already calculated, $U_A$ can be calculated using equation (1.1) as well:
\begin{align*}
  U_A&=\frac{3}{2}PV \\
  U_A&=\frac{3}{2}*10^5*10^{-3}\\
  U_A&=150J
\end{align*}

Now, the problem I'm facing is that the first align* tag is not aligned with the second one, I mean the equations are shifted. I'm not 100% sure why this happens or how to fix this.

marked as duplicate by Werner, egreg, Peter Grill, barbara beeton, lockstep Jan 22 '14 at 21:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Jan 22 '14 at 20:51

This question came from our site for professional and enthusiast programmers.

  • Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner Jan 25 '14 at 18:46
6

use \intertext:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align*}
  dU         &=\partial Q - \partial W \\
  \partial Q &= dU + \partial W
%
\intertext{Since $U_E$ was already calculated, $U_A$ can be calculated 
           using equation (1.1) as well:}
%
  U_A        &= \frac{3}{2}PV           \\
  U_A        &= \frac{3}{2}*10^5*10^{-3}\\
  U_A        &= 150J
\end{align*}

\end{document}
  • Sorry about the late answer - I just tried this and it worked. Thank you very much! :) – ivanempire Feb 1 '14 at 20:54
  • In case of one or two interrupting paragraphs, what is the best way to do so? – Diaa Jun 27 '18 at 20:40
1

For keeping equations aligned I prefer using the array environment, i.e.

\begin{array}{ } 
    <similar syntax to align>
\end{array}

I've never noticed the problem you are mentioning with equations between multiple array environments not lining up consistently.

I think the other thing you have to get used to with using LaTeX is that there are things which you aren't really supposed to control because LaTeX by default does the right thing, even if it is contrary to what you have gotten used to doing from using ms word or other word processing software. LaTeX is WYSIWYM. Just worry about the structure of your document and trust LaTeX to make it look right.

  • Well I do trust it - and the result is that it doesn't align it properly. :P Thanks though, I did use array, and I got a similar situation. I wanted to attach a screenshot but couldn't yet. – ivanempire Feb 1 '14 at 20:55

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