# align two piecewise functions

I have problem with my piecewise functions

I read others post and I tried this but I have errors

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
$x_{{i}{j}}$ =
&\begin{cases}
\text{1,} &\quad\text{Si se envía agua desde área i ( i $\in$   \{1,2,3,4,5,6,7,8,9,10\}) a sitio j ( j $\in$  \{1,2,3,4,5,6,7\})} \\
\end{cases}\\
$y_{j}$ =
&\begin{cases}
\text{1,} &\quad\text{  Si se construye planta en el sitio j ( j $\in$   \{1,2,3,4,5,6,7\})} \\
\end{cases}
\end{align*}
\end{document}


Runaway argument? ! Paragraph ended before \align* was complete. \par l.592

I did this (using [) and it works well but they appear not aligned

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$x_{{i}{j}} = \begin{cases} \text{1,} &\quad\text{Si se envía agua desde área i ( i \in \{1,2,3,4,5,6,7,8,9,10\}) a sitio j ( j \in \{1,2,3,4,5,6,7\})} \\ \text{0,} &\quad\text{En caso contrario} \end{cases}$
$y_{j} = \begin{cases} \text{1,} &\quad\text{ Si se construye planta en el sitio j ( j \in  \{1,2,3,4,5,6,7\})} \\ \text{0,} &\quad\text{En caso contrario} \end{cases}$

\end{document}


and I want they are aligned, like this

• remove the  around x_{ij} and y_{j}. \begin{align*} is already a math environment. – Troy Nov 30 '18 at 17:00 • lol I did that and it didn't work before but now it works hahaha thanks man!! is there a way to align the functions using [ .... ] ? – EmiliOrtega Nov 30 '18 at 17:02 • Yes, with the \begin{aligned} environment from amsmath. E.g. of its use: Alignment in equations – Troy Nov 30 '18 at 17:04 ## 3 Answers Beware! align already typesets its contents in math mode (but \text reverts to text mode). You have to just align the equals signs with &=; for the long line, I suggest a tabular. Some vertical spacing will help, too. \documentclass{article} \usepackage{amsmath} \begin{document} \begin{align*} x_{ij} &= \begin{cases} 1, &\begin{tabular}[t]{@{}l@{}} Si se envía agua desde área i (i\in\{1,2,3,4,5,6,7,8,9,10\}) \\ a sitio j (j\in\{1,2,3,4,5,6,7\}) \end{tabular} \\[4ex] 0, &\text{En caso contrario} \end{cases}\\ y_{j} &= \begin{cases} 1, &\text{Si se construye planta en el sitio j (j\in\{1,2,3,4,5,6,7\})} \\[1ex] 0, &\text{En caso contrario} \end{cases} \end{align*} \end{document}  Here it is I simplified the text part typing using the cases* environment from mathtols (needless to load àmsmath). I had to dplit the first case to make it fit the margins: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[showframe]{geometry} \usepackage{mathtools} \begin{document} \begin{align*} x_{{i}{j}} & = \begin{cases*} \text{1,} &\quad Si se envía agua desde área  i\: ( i \in \{1,2,3,4,5,6,7,8,9,10\}) \\ & \quad a sitio  j\: ( j \in \{1,2,3,4,5,6,7\}) \\ \text{0,} &\quad{En caso contrario} \end{cases*}\\[1.5ex] y_{j} & = \begin{cases*} 1, &\quad Si se construye planta en el sitio  j\: ( j \in \{1,2,3,4,5,6,7\}) \\ 0, &\quad En caso contrario \end{cases*} \end{align*} \end{document}  If we go back to your original attempt, a few quick changes gives the result you wanted. This: removes the  around x_{ij} and y_j and moves the & you use for alignment to align the equals signs. Edit: I also compressed the set notation to shorten the long line and returned i and j to math mode, as you currently have them as subscripts in math mode. If you'd prefer them to be set upright you should change the subscripts as well.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x_{ij} &=
\begin{cases}
\text{1,} &\quad\text{Si se envía agua desde área $i$ ($i \in \{1,2,\dots,10\}$) a sitio $j$ ($j \in \{1,2,\dots,7\}$)} \\
\end{cases}\\
y_{j} &=
\begin{cases}
\text{1,} &\quad\text{  Si se construye planta en el sitio $j$ ($j \in \{1,2,\dots,7\}$)} \\

• Since i and j are used in math mode on the LHS, it seems appropriate to use $i$ ($i \in \{1,\dots,10\}$) and $j$ ($j \in \{1,\dots,7\}$)` on the RHS. – Werner Nov 30 '18 at 17:17