Graphics, Figures & TablesVertically Alignment of Table Cell Content not properly

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
daviddoria
Posts: 60
Joined: Tue Sep 30, 2008 9:24 pm

Vertically Alignment of Table Cell Content not properly

Post by daviddoria »

I am trying to vertically center content in a table cell. I came up with this after some googling:

Code: Select all

\documentclass{article}
\usepackage{array}
 
\begin{document}
\begin{table}
\centering
\caption{MyCaption}
\begin{center}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} |p{5cm}|m{3in}|c|} %is there a way to use m without a specific length, and just say "center it"?
 
\hline
big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text big text & Column2 Title Goes here & Column3 title here\\
\hline
\end{tabular*}
 
\end{center}
 
\end{table}
 
\end{document}
but it does not work as I'd like (there are multiple obvious problems, namely, that the text is not vertically centered in the second cell). The idea of the example is to have a lot of text in the first cell, vertically centered short text in the second cell, and non-vertically centered (normal) text in the third cell. Any tips on where I'm going wrong?

Thanks,

David
Last edited by localghost on Mon Mar 05, 2012 10:41 am, edited 2 times 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

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Vertically Alignment of Table Cell Content not properly

Post by kaiserkarl13 »

I think the problem is linked to a misinterpretation of what the m{}, p{}, and b{} types do from the array package. Recall that \parbox{width}{text} creates text whose base line matches the base line of the surrounding text. Thus if you want the text in column 2 to match the center of column 1, column 1 should be in an m{}-style tabular column, not column 2.

Column 3 should be in a p{}-style tabular column to match that idea, from your description.
daviddoria
Posts: 60
Joined: Tue Sep 30, 2008 9:24 pm

Vertically Alignment of Table Cell Content not properly

Post by daviddoria »

Ok, getting closer. You are right, with this:

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} |m{5cm}|c|p{5cm}|}

column 2 is indeed centered vertically. However, is there a way to do this without specifying the '5cm' in the m{}? Also, the table is "broken" as shown in the attached table.jpg - how would I fix that?
Attachments
table.jpg
table.jpg (49.78 KiB) Viewed 2711 times
Post Reply