# Formula doesn't fit, equation number strolls behind (using flalign)

I have spent some time already trying to fix the way this formula looks, but to no avail. Does anyone have an idea on how to make this look better? Mainly the equation number should fit to the right of the equation.

\begin{flalign} \label{eqRWnaRO}
PGW_i =
&\begin{cases}
PGW_{max},& \text{if } PGW_{i-1} - Q_{PGW,Use}+ MBR_{rec} \ldots \\ &\quad *Q_{GW} + RO_{rec}*Q_{RW,PGW} \geq PGW_{max}\\
0,& \text{if } PGW_{i-1} -  Q_{PGW,Use}+ MBR_{rec} \ldots \\ &\quad *Q_{GW} + RO_{rec}*Q_{RW,PGW} \leq 0 \\
PGW_{i-1} -  Q_{PGW,Use} + MBR_{rec} \ldots \\ \quad *Q_{GW} + RO_{rec}*Q_{RW,PGW},& \text{otherwise}
\end{cases}&&
\end{flalign}


• Welcome to TeX SX! Do you want the equation number be centred w.r.t. the group? – Bernard Apr 14 at 9:30
• please post a complete small document not just a fragment, in particular for this question it is important to know the text width. But as a general comment never use math italic for multi-letter words use \mathrm{rec} or \mathit{rec} not rec 9and same for Use, max etc – David Carlisle Apr 14 at 9:36
• Hi, I used all the replies with great results! For future reference, how do I see text width? I'm new to the TEX scene. – Arjen Apr 14 at 19:49

Here is a way, using the \mathrlap command from mathtools at the end of the line which a little too long. I added a variant with a slightly simpler code, using the fleqn environment from nccmath, since you don't seem to have any alignment:

\documentclass{article}
\usepackage{geometry}
\usepackage{mathtools, nccmath}

\begin{document}

\begin{flalign} \label{eqRWnaRO}
PGW_i =
&\begin{cases}
PGW_{\max},& \text{if } PGW_{i-1} - Q_{PGW,Use}+ MBR_\mathrm{rec} \ldots \\
&\quad *Q_{GW} + RO_\mathrm{rec}*Q_{RW,PGW} \geq \mathrlap{PGW_{\max}}\\
0,& \text{if } PGW_{i-1} - Q_{PGW,Use}+ MBR_\mathrm{rec} \ldots \\
&\quad *Q_{GW} + RO_\mathrm{rec}*Q_{RW,PGW} \leq 0 \\
PGW_{i-1} - Q_{PGW,Use} + MBR_\mathrm{rec} \ldots \\ \quad *Q_{GW} + RO_\mathrm{rec}*Q_{RW,PGW},& \text{otherwise}
\end{cases}&&
\end{flalign}\bigskip

\begin{fleqn}
$$\label{eqRWnaRO} PGW_i = \begin{cases} PGW_{\max},& \text{if } PGW_{i-1} - Q_{PGW,Use}+ MBR_\mathrm{rec} \ldots \\ &\quad *Q_{GW} + RO_\mathrm{rec}*Q_{RW,PGW} \geq \mathrlap{PGW_{\max}}\\ 0,& \text{if } PGW_{i-1} - Q_{PGW,Use}+ MBR_\mathrm{rec} \ldots \\ &\quad *Q_{GW} + RO_\mathrm{rec}*Q_{RW,PGW} \leq 0 \\ PGW_{i-1} - Q_{PGW,Use} + MBR_\mathrm{rec} \ldots \\ \quad *Q_{GW} + RO_\mathrm{rec}*Q_{RW,PGW},& \text{otherwise} \end{cases}$$
\end{fleqn}

\end{document}


I had to guess the line width based on your image, but changes:

avoid math italic for multi-letter names, avoid multi-line constructs like fleqn for single line displays, add a \jot extra space between the lines of the cases, and I also dropped the commas.

\documentclass{article}
\usepackage{amsmath}
\addtolength\textwidth{72pt}% more or less as shown in question
\begin{document}

aaa
\begin{flalign} \label{eqRWnaRO}
PGW_i =
&\begin{cases}
PGW_{max},& \text{if } PGW_{i-1} - Q_{PGW,Use}+ MBR_{rec} \ldots \\ &\quad *Q_{GW} + RO_{rec}*Q_{RW,PGW} \geq PGW_{max}\\
0,& \text{if } PGW_{i-1} -  Q_{PGW,Use}+ MBR_{rec} \ldots \\ &\quad *Q_{GW} + RO_{rec}*Q_{RW,PGW} \leq 0 \\
PGW_{i-1} -  Q_{PGW,Use} + MBR_{rec} \ldots \\ \quad *Q_{GW} + RO_{rec}*Q_{RW,PGW},& \text{otherwise}
\end{cases}&&
\end{flalign}

bbb
$$\label{eqRWnaROb} \mathrm{PGW}_i = \begin{cases} \mathrm{PGW}_{\max}& \text{if } \mathrm{PGW}_{i-1} - Q_{\mathrm{PGW},\mathrm{Use}}+ \mathrm{MBR}_{\mathrm{rec}} \ldots \\ &\quad *Q_{GW} + RO_{\mathrm{rec}}*Q_{RW,\mathrm{PGW}} \geq \mathrm{PGW}_{\max}\\[\jot] 0& \text{if } \mathrm{PGW}_{i-1} - Q_{\mathrm{PGW},\mathrm{Use}}+ \mathrm{MBR}_{\mathrm{rec}} \ldots \\ &\quad *Q_{GW} + RO_{\mathrm{rec}}*Q_{RW,\mathrm{PGW}} \leq 0 \\[\jot] \mathrm{PGW}_{i-1} - Q_{\mathrm{PGW},\mathrm{Use}} + {}\\ \quad \mathrm{MBR}_{\mathrm{rec}} \ldots & \text{otherwise} \\ \quad *Q_{GW} + RO_{\mathrm{rec}}*Q_{RW,\mathrm{PGW}} \end{cases}$$

\end{document}


Rather than feature the repeated expression PGW_{i-1} - Q_{PGW,Use} + MBR_{rec} \cdot Q_{GW} + RO_{rec}\cdot Q_{RW,PGW} fully three [3!] times inside a single cases environment, I'd give it a name (say, \theta(PGW_{i-1})), state it up front, and then simplify the contents of the cases environment considerably. (You are obviously free to come up with another function name that \theta!) Your readers might appreciate that you made an effort to keep the visual presentation of your material as clutter-free as possible.

In the following code, note the use of the \vn macro (short for "variable name", I suppose) to typeset variable names more compactly than if they written out in ordinary math mode.

\documentclass{article}
\usepackage{amsmath}  % for 'cases' environment
\newcommand\vn[1]{\mathit{#1}} % typeset variable names

\begin{document}
Put $\theta(\vn{PGW}_{\!i-1})=\vn{PGW}_{\!i-1} - Q_{\vn{PGW},\vn{Use}} + \vn{MBR}_{\vn{rec}} \cdot Q_{\vn{GW}} + \vn{RO}_{\vn{rec}}\cdot Q_{RW,\vn{PGW}}$;
then,
$$\label{eqRWnaRO} \vn{PGW}_{\!i} = \begin{cases} \vn{PGW}_{\!\max} & \text{if }\theta(\vn{PGW}_{\!i-1})\geq\vn{PGW}_{\!\max}\\ 0 & \text{if }\theta(\vn{PGW}_{\!i-1})\leq 0, \\ \theta(\vn{PGW}_{\!i-1}) & \text{otherwise.} \end{cases}$$

\end{document}