GeneralHow to vertically center an equation in a merged row?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

How to vertically center an equation in a merged row?

Post by yoyoimut »

Dear all,

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:

Code: Select all

Code, edit and compile here:
\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}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
With the output as follows:
verticallyCentered.jpg
verticallyCentered.jpg (51.21 KiB) Viewed 5201 times

Is there a way to make it vertically centered without doing trial and error adjustments?


Thank you in advance.

regards,

Yoyo
Last edited by yoyoimut on Wed Nov 24, 2010 4:36 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

How to vertically center an equation in a merged row?

Post by php1ic »

I think the formula in your MWE is vertically centered over 3 standard rows. By expanding the height with \parbox the alignment is lost.

Try changing the distance between rows to get vertical alignment

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{multirow,longtable,array}
\begin{document}
\renewcommand{\arraystretch}{2}
\begin{tabular}{|p{5cm}|p{5cm}|}
\hline
Description & Formula\\
\hline
\multirow{3}{*}{$\displaystyle \int_a^b f(x)\, \textrm{d}x=F(b)-F(a)$} & A\\
\cline{2-2}
& B \\
\cline{2-2}
& C \\
\hline
D & E \\
\hline
\end{tabular}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
yoyoimut
Posts: 120
Joined: Mon Oct 19, 2009 6:58 am

How to vertically center an equation in a merged row?

Post by yoyoimut »

I got a nice solution from "CV Radhakrishnan" using nested tabular as follows:

Code: Select all

Code, edit and compile here:
\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}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Post Reply