I have an equation in a multi row cell (aka a merged cell) that should be vertically centered. I do using the following code snippet:
\documentclass{article}
\usepackage
{
multirow,
longtable,
array
}
\begin{document}
\begin{tabular}{|*{2}{c|}}\hline
\parbox[c][1cm]{5cm}{Description} & \parbox[c][1cm]{5cm}{Formula}\\\hline
\multirow{3}*
{
\parbox[c]开发者_如何学编程[1cm]{5cm}
{
\centering$\displaystyle \int_a^b f(x)\, \textrm{d}x=F(b)-F(a)$
}
}
&\parbox[c][1cm]{5cm}{ A } \\\cline{2-2}
&\parbox[c][1cm]{5cm}{ B } \\\cline{2-2}
&\parbox[c][1cm]{5cm}{ C } \\\hline
\parbox[c][1cm]{5cm}{D} & \parbox[c][1cm]{5cm}{E}\\\hline
\end{tabular}
\end{document}
Is there a way to make it vertically centered without doing trial and error adjustments?
I've spent some time with it without really solving it. You could of course increase the second argument to parbox
from 1cm to 3cm since each cell is 1cm high (give or take a few mm). But how to expand the parbox to exactly fill the cell I can't figure out. Not even sure it's possible.
Perhaps you could use
\newlength{\threecells}
\settoheight{\threecells}{a tabular of three cells}
and then use \threecells
in your second argument.
Instead of using \multirow for first cell, putting the three rows in a tabular inside second cell can solve the problem. That gives you the freedom of ignoring the height of second cell.
\documentclass{article}
\usepackage{multirow,longtable,array}
\begin{document}
\begin{tabular}{|*{2}{c@{}|@{}}}
\hline
\parbox[c][1cm]{5cm}{Description}
& \parbox[c][1cm]{5cm}{~~~Formula}\\\hline
$\displaystyle \int_a^b f(x)\,
\textrm{d}x=F(b)-F(a)$
&\begin{tabular}{@{}l@{}}
\parbox[c][1cm]{5cm}{~~ A } \\\hline
\parbox[c][1cm]{5cm}{~~ B } \\\hline
\parbox[c][1cm]{5cm}{~~ C } \\
\end{tabular}\\\hline
\parbox[c][1cm]{5cm}{D} & \parbox[c][1cm]{5cm}{~~~E}\\\hline
\end{tabular}
\end{document}
精彩评论