Graphics, Figures & TablesTabular, parbox, vertical alignment

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
cacajean
Posts: 4
Joined: Fri Feb 04, 2011 7:02 pm

Tabular, parbox, vertical alignment

Post by cacajean »

Hello,

What i want to achieve is really simple:

I want to be able to align cell content at the top (which is the default behavior of tabular) while being able to manually break lines (and anything you could normally do in a paragraph environment). For instance:

Image

I would expect this to work:

\begin{tabular}{|r|l|}
\hline
\parbox{3cm}{\raggedleft First Line\\SecondLine} &
\parbox{5cm}{\textbf{First line goes here}\\
Second line would be here\\
And so on, ...\\
... until the very end.} \\
\hline
\end{tabular}

However this produces the following result:

Image

The left parbox is vertically centered. During the past two days, I've searched the whole LaTeX community in vain for a solution to this problem. I've come across solutions consisting in the use of raisebox that force you to manually grope for the right difference value depending on the content of the two cells. That is no solution to me. I want this to be automatic as it is in any document editor... I would be very surprised if LaTeX didn't allow this kind of construction!

Thank you!

Recommended reading 2024:

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

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

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Tabular, parbox, vertical alignment

Post by frabjous »

Code: Select all

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{|>{\raggedleft}p{3cm}|>{\raggedright\arraybackslash}p{5cm}|}
\hline
First line\\ Second line
&
\textbf{First line goes here}\newline
Second line would be here\newline
And so on, \ldots \newline 
\ldots\ until the very end. \\
\hline
\end{tabular}
\end{document}
table.png
table.png (3.27 KiB) Viewed 11523 times
cacajean
Posts: 4
Joined: Fri Feb 04, 2011 7:02 pm

Re: Tabular, parbox, vertical alignment

Post by cacajean »

Thanks a lot!
This looks like it's perfectly working.
However what if I want to use an eqparbox on the first column instead?
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Tabular, parbox, vertical alignment

Post by frabjous »

Try it and see. (The array package uses regular parboxes in the underlying code -- see its documentation.) Without a more specific question and some sample code, I'm at a loss to know how to respond.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Tabular, parbox, vertical alignment

Post by frabjous »

By the way, according to the Board Rules, when you also post the question somewhere else as well, you are supposed to tell us that.

Tabular, parbox, vertical alignment at TeX SE
Post Reply