LaTeX forum ⇒ Graphics, Figures & TablesTabular, parbox, vertical alignment

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

Tabular, parbox, vertical alignment

Postby cacajean » Fri Feb 04, 2011 7:06 pm

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!

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

Postby frabjous » Fri Feb 04, 2011 7:40 pm

  1. \documentclass{article}
  2. \usepackage{array}
  3. \begin{document}
  4. \begin{tabular}{|>{\raggedleft}p{3cm}|>{\raggedright\arraybackslash}p{5cm}|}
  5. \hline
  6. First line\\ Second line
  7. &
  8. \textbf{First line goes here}\newline
  9. Second line would be here\newline
  10. And so on, \ldots \newline
  11. \ldots\ until the very end. \\
  12. \hline
  13. \end{tabular}
  14. \end{document}

table.png
table.png (3.27 KiB) Viewed 6030 times

cacajean
Posts: 4
Joined: Fri Feb 04, 2011 7:02 pm

Postby cacajean » Fri Feb 04, 2011 7:55 pm

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

Postby frabjous » Fri Feb 04, 2011 8:04 pm

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

Postby frabjous » Fri Feb 04, 2011 8:25 pm

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


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 6 guests