GeneralVertical align within a cell in a tabular environment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
pittopitto
Posts: 2
Joined: Mon Oct 15, 2007 12:45 am

Vertical align within a cell in a tabular environment

Post by pittopitto »

Hello guys,

I have a question for you... Hope it's not too hard.

I have created a {table} environment and inside of it a {tabular} environment.
There are three columns and 10 rows. In the first column I've put graphical schemes and in the other two columns the predictions and observations of my analysis, that are NOT graphical, but equations.

Now, because of the graphics in the first column, the rows are actually taller than normal which is normal, but the equations in the second and third column are vertically aligned at the bottom making the table looking VERY ugly.
I've been searching, unsuccessfully, over the net on how could I center align the content of each cell in the table BOTH vertically and horizontally. Yeah, I want the equations at the center of the cells. Any idea???

Please help!

Many Thanks

Gianluca

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

balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: Vertical align within a cell in a tabular environment

Post by balf »

It's not very easy to help without having any idea of the code you used...

B.A.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Vertical align within a cell in a tabular environment

Post by Juanjo »

Load the array package and try the m descriptor. Look at the manual here. Just a small example:

Code: Select all

\begin{tabular}{m{3cm}m{3cm}}
   \rule{2cm}{5cm} & $E=mc^2$ \\
   \rule{2cm}{5cm} & $E=mc^2$ \\
   \rule{2cm}{5cm} & $E=mc^2$ 
\end{tabular}
The \rule commands replace the \includegraphics ones in your code.
qwe
Posts: 1
Joined: Sun Mar 30, 2008 3:51 pm

Re: Vertical align within a cell in a tabular environment

Post by qwe »

Hi,

I have a problem similar to pittopitto's and tried the array package but it didn't help me.

I have a table with two narrow left-aligned columns, a column with a formula which should be aligned in the middle of the cell (horizontally and vertically) and a fourth column with a (long) paragraph of text.

The column with the formula should resize to the with of the widest formula. The last column with the paragraph determines the height of each row depending on the length of the text.

First I defined the table this way which aligns the formula at the top
\begin{tabular}{|l|l|c|p{40mm}|}

Juanjo's example works in his example but the following aligns my formulae at the top-left...
\begin{tabular}{|l|l|m{60mm}|p{40mm}|}

What am I missing? I've also been searching, the following came closest but didn't solve the issue http://start.it.uts.edu.au/w/doc/LaTeX/tabular.html

Help! :'(

Q
balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: Vertical align within a cell in a tabular environment

Post by balf »

Your third column with formulae (math formulae, I suppose) should be called with
\begin{tabular}{|l|l|>{\centering $}m{60mm}<{$}|p{40mm}|}
I don't know whether it it will solve your problem, but it is the correct syntax to obtain centered formulae. If it doesn't solve anything, what is your preamble?

B.A.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Vertical align within a cell in a tabular environment

Post by Juanjo »

What about this other example?

Code: Select all

\begin{tabular}{|l|l|>{$\displaystyle}c<{$}|>{\raggedright}m{40mm}|}
  \hline
  blah & blah & \frac{x^2-1}{x-1}=x+1 & 
  blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
  blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah \tabularnewline
  \hline
  blah & blah &  \frac{x^3-1}{x-1}=x^2+x+1  & 
  blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah \tabularnewline
  \hline
\end{tabular}

You can replace \tabularnewline by \\ if you remove the \raggedright declaration.
Post Reply