# Align equation with conditions and another equation

I would like to align 6 and 7 with equation 8 and 9. I wish to align this at the equals sign.

What I have now:

which I got using the code below:

    \begin{numcases}{O(t) =}
\textbf{W}^T S(t), & $\text{if } S(t) \in Signal$; \\
\textbf{0}, & \text{if } otherwise,
\end{numcases}

\begin{align}
CSM &= \pi_{1} (O(t)) \label{eq:pi1} \\[10pt]
K &= \pi_{2} (O(t)) \label{eq:pi2} \
\end{align}


What I need:

• Wouldn't it be more sensible to number the cases as, say, 6aand 6b. Commented Feb 14, 2018 at 22:03
• yeah @Bernard that would make sense also. But right now my problem lies in aligning the number cases and the two other equations 8 and 9. Commented Feb 14, 2018 at 22:04
• @obiigbe91 Do you really need separate number for the cases of zero and the other(?), or one number for the whole equation would be ok? Asking because the default for math and latex is to give one number to the whole equation... Since it is just the O(t)... Offtopic: "If otherwise" is bad English even for me.. that I am really bad in English ("otherwise" contains an if) Commented Feb 14, 2018 at 22:10
• @koleygr I would like them to be in separate numbers. But the numcases can be 6a and 6b like Bernard pointed out Commented Feb 14, 2018 at 22:14

Here is just one option:

\documentclass{article}

\usepackage{mathtools,cases,xparse,eqparbox}

% https://tex.stackexchange.com/a/34412/5764
\makeatletter
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
\IfValueTF{#1}
{\def\eqmathbox@##1##2{\eqmakebox[#1][#2]{$##1##2$}}}
{\def\eqmathbox@##1##2{\eqmakebox{$##1##2$}}}
\mathpalette\eqmathbox@{#3}
}

\newcommand{\startsubequations}{%
\refstepcounter{equation}%
\protected@xdef\theparentequation{\theequation}%
\global\let\theoldequation\theequation
\setcounter{parentequation}{\value{equation}}%
\setcounter{equation}{0}%
\gdef\theequation{\theparentequation\alph{equation}}%
}

\newcommand{\stopsubequations}{%
\protected@xdef\theequation{\theparentequation}%
\global\let\theequation\theoldequation
\setcounter{equation}{\value{parentequation}}%
}

\makeatother

\newcommand{\LBRACE}{
\left\lbrace\begin{array}{@{}c@{}}
\strut \\ \strut
\end{array}\right.\kern-\nulldelimiterspace
}

\begin{document}

\begin{numcases}{O(t) =}
\mathbf{W}^T S(t), & if $S(t) \in \text{Signal}$; \\
\mathbf{0}, & otherwise,
\end{numcases}
\begin{align}
CSM &= \pi_1 (O(t)) \\
K &= \pi_2 (O(t))
\end{align}

\noindent\hrulefill

\begin{align}
%\startsubequations % Start subequation numbering
& \hphantom{\LBRACE}\eqmathbox[nc][l]{\mathbf{W}^T S(t), \quad} \text{if $S(t) \in \text{Signal}$;} \\
\raisebox{.5\dimexpr\baselineskip+\jot}[0pt][0pt]{$O(t) ={}$} &
\raisebox{.5\dimexpr\baselineskip+\jot}[0pt][0pt]{$\LBRACE$}
\eqmathbox[nc][l]{\mathbf{0},} \text{otherwise,} \\
%\stopsubequations % Stop sub-equation numbering
CSM ={} & \pi_1 (O(t)) \\
K ={} & \pi_2 (O(t))
\end{align}

\end{document}


The approach fakes a numcases environment by placing four regular equations in an align. The grouping of the first two is done by moving the left-hand side O(t) = and the left delimiter { into place (vertically upward) from the second equation.

Some box width calculations are automated using eqparbox for the different conditions.

Spacing between the left brace grouping and conditions and textual components can be changed, if needed.

...and if you want to sub-number the equations you can use the ConTeXt-esque approach of \startsubequations ... \stopsubequations:

I can get what you want with a horrible code, adjusting fake lengths:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage[table]{xcolor}
\usepackage{mathtools}
\usepackage{cases}
\begin{document}

\begin{align}%
O(t) &= {} \hspace*{-1.35cm}\makebox[0.3\linewidth]{\begin{subnumcases}{\hspace*{3.08cm}}
\textbf{W}^T S(t), & if $S(t) \in$ Signal; \\
\textbf{0}, & otherwise,
\end{subnumcases} }\notag
\\[1ex]
CSM &= \pi_{1} (O(t)) \label{eq:pi1}
\\[1ex]
K &= \pi_{2} (O(t)) \label{eq:pi2} \
\end{align}% \end{subequations}

\end{document}