# align separate equations [duplicate]

This question already has an answer here:

I have the following structure in my tex

Part of this paper has this structure where there are many short one-two line explanations cut by one line equations

$$\label{s1} y=z+r+c$$


with again the same structure repeating for several pages. The text in between these equation is about 4-5 lines, on average.

$$\label{s2} y_{321}=z_3+r_2+c_1$$


Now, these equations are all one-liners but the lhs/rhs are of quiet varying length

$$\label{s2} z_{123}+\omega+\Theta+y_{321}=z_3+r_2+c_1$$


so the central equality sign tends to jump around horizontally quiet a lot from one paragraph to the next.

$$\label{s2} z_3+r_2+c_1\thereforz_{123}+\omega+\Theta+y_{321}$$


Note that furthermore each of the equations is short and doesn't occupy the whole line, so there is space to align them horizontally.

I think this irregularity looks a bit untidy.

My question is: is there a way to align (at least the equality signs in) equation s1 and s2?

## marked as duplicate by Hendrik Vogt, Mensch, Heiko Oberdiek, Claudio Fiandrino, ThorstenMay 22 '13 at 16:48

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.

• align plus \intertext{...} – daleif May 22 '13 at 11:29

## 3 Answers

You can use either \shortintertext from mathtools or \intertext from amsmath.

\documentclass{article}

\usepackage{mathtools}

\begin{document}

\begin{align*}
AAA &= BBBBBBBBBB,\\
\shortintertext{and}
C   &= DD.
\end{align*}
or
\begin{align*}
AAA &= BBBBBBBBBB,\\
\intertext{and}
C   &= DD.
\end{align*}

\end{document}


The difference between the two command is the spacing around the text between the aligned equations.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

blabla-bla-bla

\begin{align}
y&=z+r+c  \label{s1}\\
\noalign{\text{blabla-blah} }
y_{321}&=z_3+r_2+c_1 \label{s2}
\end{align}

\end{document}


• Is it true that this will align only those two equations? That is, would it be tough to use this approach through the document to align all equal signs? – Steven B. Segletes May 22 '13 at 11:35
• @StevenB.Segletes It is not that OP wants, I hope. Hovever, your suggestion is very interesting. – Przemysław Scherwentke May 22 '13 at 11:39
• Actually, that is what the OP was wondering about... – user1933 May 22 '13 at 13:20

Taking the user's question a step further, I have created the algneqn environment which will align the equation contents on the tab character. The user must specify two constrained parameters (fractions of textwidth for left and right side of alignment) that will govern where that alignment tab is set on the horizontal line. And unlike \intertext solutions, which are great for aligning equations with a small amount of text in between them, this one may be invoked across the whole document, without the use of any intertext. EDITED to clean up solution, and show more example of usage. REDITED to ignore spaces after leaving equation environment.

\documentclass{article}

\def\leftalgn{0.45}\def\rightalgn{0.45}
\def\algnrow{\rule{\leftalgn\textwidth}{0ex}&\rule{\rightalgn\textwidth}{0ex}}
% CONSTRAINTS:
% equation label must fit in {1 -\leftalgn -\rightalgn}\textwidth
% \leftalgn must be larger than any text to left of align character
% \rightalgn must be larger than any text to right of align character
\newenvironment{algneqn}{%
\arraycolsep=0ex\renewcommand\arraystretch{0}%
$$% \begin{array}{rl}% \algnrow\\}% {\\\algnrow% \end{array}%$$\ignorespacesafterend%
}
\def\snug#1{\vspace*{-#1\baselineskip}}
\begin{document}
I will align all equal signs using the newly created \verb|algneqn|
environment, which can be used throughout the document.  I am setting
\verb|\leftalgn| to 0.45 and \verb|\rightalgn| to 0.45, and setting the
tab character before the equal sign.
\begin{algneqn}\label{s1}
y&=z+r+c
\end{algneqn}
blabla-blah...blabla-blah...blabla-blah...blabla-blah...
\begin{algneqn}\label{s2}
y_{321}&=z_3+r_2+c_1 + x
\end{algneqn}
blabla-blah...blabla-blah...blabla-blah...blabla-blah...
\begin{algneqn}\label{s2}
y_{321} - \left(z_3+r_2+c_1 + x\right) &= 0
\end{algneqn}
blabla-blah...blabla-blah...blabla-blah...blabla-blah...

Now, I will try a constant indent by resetting the two parameters:
\verb|\leftalgn| to 0.1 and \verb|\rightalgn| to 0.8.  Then, I set tab
character at the beginning of equation.
\def\leftalgn{0.1}\def\rightalgn{0.8}
\begin{algneqn}\label{s1}
&y=z+r+c
\end{algneqn}
blabla-blah...blabla-blah...blabla-blah...blabla-blah...
\begin{algneqn}\label{s2}
&y_{321}=z_3+r_2+c_1 + x
\end{algneqn}
blabla-blah...blabla-blah...blabla-blah...blabla-blah...\\
I have introduced the \verb|\snug{}| command to take care of the fact
that short-width \verb|algneqn|'s will not autosnug\\
SHORT
\snug{.8}% THIS \snug IS TO CORRECT FACT THAT algneqn WILL NOT AUTO-SNUG
\begin{algneqn}\label{s2}
&y_{321} - \left(z_3+r_2+c_1 + x\right) = 0
\end{algneqn}
blabla-blah...blabla-blah...blabla-blah...blabla-blah...

\small
\verb|CONSTRAINTS:|\\
\verb|equation label must fit in {1 -\leftalgn -\rightalgn}\textwidth|\\
\verb|\leftalgn must be larger than any text to left of align character|\\
\verb|\rightalgn must be larger than any text to right of align character|
\end{document}


This approach was revised at Align all equal signs in the document, in order to handle multi-line equations.

• the idea is...awesome. But it causes an un-holly amount of problems in the text...I suppose I will play with the parameters a bit....So there are no simple ways to do that? – user1933 May 22 '13 at 13:21
• @user1933 Try this cleaned up version. See if it works better for you. – Steven B. Segletes May 22 '13 at 13:47
• @user1933 The one place (at least) where this approach will look "bad" is when a short algneqn occurs after a short line of text. This is because the \algnrow is typeset across basically the whole line, even if the visible part of the equation is short. Thus, whereas LaTeX would normally snug the equation upward in such a case, it won't perceive that the equation is horizontally narrow. Thus, no snugging will take place. Thus, I introduce \snug to be manually applied when needed. – Steven B. Segletes May 22 '13 at 14:57