# How to align an equation using amsmath

Can somebody explain to me how to put this in proper LaTeX-Code?

I am really not sure... let's see:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\sum_{(i,j)\el E} x_(i,j)^(s,d) - \sum_{(i,j)\el E} x_(j,i)^(s,d) =
\begin{cases}
1 &\text{if i=s} \\
-1 &\text{if i=d} &\forall s,d,i \el V \\
0 &\text{otherwise}
\end{cases}
\end{align}
\end{document}


I am almost sure the sub- and superscripts will not look nice this way. But the problem is also: I get an error saying "undefined control sequence \end{align}" In order to be able to use the align-environment I should only need to import amsmath, is that correct?

• do you use texstudio? – David Carlisle Oct 31 '18 at 9:43
• thx so much guys! You really helped me a lot – user503842 Oct 31 '18 at 10:38

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{gather*}
\sum\limits_{(i,j)\in E}x_{i,j}^{s,d}-\sum\limits_{(j,i)\in E}x_{j,i}^{s,d} =
\begin{cases}
1 & \mbox{if } i = s \\
-1 & \mbox{if } i = d \\
0 & \text{otherwise}
\end{cases}
\forall s,d,i \in V \\
\sum\limits_{(s,d)}x_{i,j}^{s,d}t^{s,d}\leq \sum\limits_{n\in [1\ldots N]}K_{n}l^{n}_{i,j}
\forall (i,j)\in E
\end{gather*}
\end{document}


I would like to add to the previous answer that instead of align, using gather* environment will allow you to center both equations and to print them without any number marks.

perhaps something like

\documentclass{article}
\usepackage{amsmath}
\begin{document}
% no alignment
\begin{gather}
\sum_{(i,j)
% \in not \el
\in
E}
% {} not ()
x_{i,j}^{s,d} - \sum_{(i,j)\in E}
% {} not ()
x_{j,i}^{s,d} =
\begin{cases}
%  math around equation
1 &\text{if $i=s$}\\
% \in not \el
-1 &\text{if $i=d \quad\forall s,d,i \in V$}\\
0 &\text{otherwise}
\end{cases}\\
\sum_{\ldots} \leq \sum_{\ldots}
\end{gather}
\end{document}


The second inequality just a sketch of course.

I propose this variant layout, with mathtools (needless to load amsmath):

\documentclass{article}
\usepackage{mathtools}

\begin{document}

\begin{alignat*}{2}
\smashoperator[r]{\sum_{(i,j)\in E}}x_{i,j}^{s,d}-\smashoperator{\sum_{(j,i)\in E}}x_{j,i}^{s,d} & =
\begin{cases}
\phantom{-}1 & \mbox{if } i = s \\
-1 & \mbox{if } i = d \\
\phantom{-}0 & \text{otherwise}
\end{cases}
&\qquad & \forall s,d,i \in V \\[1.5ex]
\sum_{(s,d)}x_{i,j}^{s,d}t^{s,d} & \leq \smashoperator{\sum_{n\in [1\ldots N]}}K_{n}l^{n}_{i,j}
& &
\forall (i,j)\in E
\end{alignat*}

\end{document}