# Align multiple equations inside tabular with case environment.

I want to align the equations inside a tabular environment, those equations contain a case environment such that the alignment becomes annoying, the following figure shows what trouble I encountered, how could I solve this problem?

The Latex codes are

\documentclass[preview]{standalone}
\usepackage{amsmath}
\usepackage[flushleft]{threeparttable}
\usepackage{makecell,booktabs}
\begin{document}
\newsavebox\CE
\begin{lrbox}{\CE}
\begin{aligned} \hat{x}^i_k & = \hat{x}^i_{k\mid {k-1}}+ K^i_k( z^{i}_k - H^i_k \hat{x}^i_{k \mid k-1})+u^i_k \notag\\ u^i_k&=C^i_k \sum_{j\in N_i}(\hat{x}^j_{{k-1}}-\hat{x}^i_{k\mid {k-1}} ) \end{aligned}
\end{lrbox}

\newsavebox\HC
\begin{lrbox}{\HC}
\begin{aligned} \begin{cases} \hat{x}^i_k & = A_k \hat{x}^i_{ {k-1}}+ K^i_k( z^{i}_k - H^i_k \hat{x}^i_{ k-1})+u^i_k \notag\\ u^i_k&=C^i_k \sum_{j\in N_i}(\hat{x}^j_{{k-1}}-\hat{x}^i_{ {k-1}} ) \end{cases}\\ & Subject To\\ \frac{1}{n}\sum_{i\in \mathcal{N}} \|\tilde{z}^i\|^2 &\leq \gamma^2 \{ \|v\|_2^2 +\frac{1}{n}\sum_{i\in \mathcal{N}} (e^i_0)^T S^i e^i_0\} \end{aligned}
\end{lrbox}
\begin{table}
\caption{The mechanisms of four consensus filtering approaches}
\centering
\begin{threeparttable}
\begin{tabular}{cc@{\qquad}}
Types  & Structures of Consensus Filters\\
\midrule\midrule
\makecell{CE} & \usebox{\CE}  \\\cmidrule(l r){1-2}
\makecell{$H_\infty$\\ consensus} & \usebox{\HC}  \\ \midrule\midrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}


## 1 Answer

I only guess how you like to your table look out: Something like this:

For above image I rewrote (simplify) your MWE:

\documentclass[border=3mm,preview]{standalone}
\usepackage{amsmath}
%\usepackage[flushleft]{threeparttable}
\usepackage{array,booktabs}
\usepackage[font=small]{caption}

\begin{document}

\begin{table}
\caption{The mechanisms of four consensus filtering approaches}
\centering
\begin{tabular}{m{22mm} m{66mm}}
Types  & Structures of Consensus Filters\\
\midrule\midrule
CE  &
\begin{aligned} \hat{x}^i_k & = \hat{x}^i_{k\mid k-1} + K^i_k(z^i_k - H^i_k \hat{x}^i_{k \mid k-1})+u^i_k \\ u^i_k & = C^i_k \sum_{j\in N_i}(\hat{x}^j_{k-1}-\hat{x}^i_{k\mid k-1}) \end{aligned}                                   \\%new row
\cmidrule(l r){1-2}
$H_\infty$\newline
consensus
&   \begin{aligned} & \begin{cases} \hat{x}^i_k = A_k \hat{x}^i_{k-1} + K^i_k(z^i_k- H^i_k\hat{x}^i_{k-1}) + u^i_k \\ u^i_k = C^i_k \sum_{j\in N_i}(\hat{x}^j_{k-1}-\hat{x}^i_{k-1}) \end{cases}\\ & \text{Subject To:}\\ & \frac{1}{n}\sum_{i\in \mathcal{N}} \|\tilde{z}^i\|^2 \leq \gamma^2 \{\|v\|_2^2 + \frac{1}{n}\sum_{i\in\mathcal{N}} (e^i_0)^T S^i e^i_0\} \end{aligned}                               \\% end of rows
\midrule\midrule
\end{tabular}
\end{table}
\end{document}


As you can see, I wrote equations directly into table. In them I omit all needlessness and also wrote "subject to" as text. I preserve left align of equations.

Instead column type c I use m{>width>} (here you can select width on your taste). This column type make vertical centered and left aligned content of cells. If you like to have horizontally centered to, than instead m{<width>} use:

>{\centering\arraybackslash}m{<width>}

I do not know, what is purpose of use threeparttable, anyway I omit it since it hasn't influence of table appearance with exception of caption. For it I rather use caption package.

Edit: Even better look out you obtain if you erase ampersand in cases environment, as suggested @egreg in his comment.

• Yes, it's what I wanted, thanks a lot, and I learned a lot from your codes which helps my future coding. – wayne Sep 26 '15 at 10:46
• There should be no & in the cases environment, or it should be aligned surrounded by \left\{ and \right. – egreg Sep 26 '15 at 11:03
• @egreg, yes, because of it, the equations look ugly. I will correct this soon. – Zarko Sep 26 '15 at 11:12
• Can't upvote twice. ;-) – egreg Sep 26 '15 at 11:23
• @WangyanLi, the threepartable can be easily add. It should not change the table design as such. You need just add for example \begin{threeparttable}[b] before caption and \end{threeparttable} after tablenotes and before \end{table}. Note, in your MWE the \begin{threeparttable} is wrong possitioned. – Zarko Sep 26 '15 at 16:54