# Vertical alignment of a table row with a multiline equation in one cell

I have a 3-by-2 table and in the 3-2 position there should be a 3-line equation. To align the equation I have used tabular, so I have a table within a table. But the 3-line equation is centered where it should be vertically aligned with the cell contents of the first column.

\documentclass{book}
\usepackage{array}

\begin{document}
\begin{tabular}{p{4.25cm}l}
cell1 & cell2 \\
cell3 & cell4 \\
cell5 & \begin{tabular}{ll} $x^2 + 5x$ & $= x^7 + 6x^4 + 1200$\\
& $= x^7 + 2x^4 + 4x^4 + 1200$ \\
& $=x^7 + 2x^4 + 4x^4 + 600 + 600$\end{tabular}
\end{tabular}

\end{document}


So "cell5" should be aligned with the first equation. How can I accomplish this?

I can think of two straightforward solutions:

• Change \begin{tabular}{ll} to \begin{tabular}[t]{ll} to inform LaTeX that entries in this row should be top- rather than center-aligned.

• For better-looking mathematics, switch to an aligned[t] environment.

The following screenshot shows the effects that aligned[t], aligned[c], and aligned[b] have on the placement of the contents of the first column.

\documentclass{book}
\usepackage{array,amsmath,booktabs}
\begin{document}
\begin{tabular}{@{}ll@{}}
cell1 & cell2 \\
cell3 & cell4 \\
\midrule
cell5 & \begin{aligned}[t] % top alignment x^2 + 5x &= x^7 + 6x^4 + 1200\\ &= x^7 + 2x^4 + 4x^4 + 1200 \\ &= x^7 + 2x^4 + 4x^4 + 600 + 600 \end{aligned}  \\
\midrule
cell7 & \begin{aligned} % "[c]" is the default x^2 + 5x &= x^7 + 6x^4 + 1200\\ &= x^7 + 2x^4 + 4x^4 + 1200 \\ &= x^7 + 2x^4 + 4x^4 + 600 + 600 \end{aligned} \\
\midrule
cell9 & \begin{aligned}[b] % bottom alignment x^2 + 5x &= x^7 + 6x^4 + 1200\\ &= x^7 + 2x^4 + 4x^4 + 1200 \\ &= x^7 + 2x^4 + 4x^4 + 600 + 600 \end{aligned} \\
\midrule
\end{tabular}

\end{document}

• Using aligned and [t] worked perfectly. I did not add the booktabs package though. What was booktabs for? Commented Jun 7, 2020 at 5:07
• @E2R0NS - The booktabs package provides various macros for well-spaced horizontal lines, including \midrule.
– Mico
Commented Jun 7, 2020 at 5:10