[Tex/LaTex] How to top align table cells of variable length

tablesvertical alignment

I would like to get the lorem ipsum text to start on the same row as "A" in the table below. How can I do this?

enter image description here

Here is my code:

\documentclass{article}
\usepackage[hmargin=3cm,vmargin=8cm]{geometry}
\usepackage{array}
\newcolumntype{B}[1]{>{\arraybackslash\hspace{0pt}}p{#1}}
\begin{document}
\begin{tabular}[t]{l@{\hspace{0.7cm}}!{\vrule width 2pt}@{\hspace{0.7cm}}B{10cm}}
X & Y \\
& \\
A \\ B & 
lorem ipsum dolor sit amet, consectetuer adipiscing elit. nam cursus. morbi ut mi. nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. sed eleifend nonummy diam. praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh. duis tincidunt lectus quis dui viverra vestibulum. suspendisse vulputate aliquam dui. nulla elementum dui ut augue. aliquam vehicula mi at mauris. maecenas placerat, nisl at consequat rhoncus, sem nunc gravida justo, quis eleifend arcu velit quis lacus. morbi magna magna, tincidunt a, mattis non, imperdiet vitae, tellus. sed odio est, auctor ac, sollicitudin in, consequat vitae, orci. fusce id felis. vivamus sollicitudin metus eget eros. \\
& \\
\end{tabular}
\end{document}

Best Answer

The simplest thing you can do is to emulate a line break with a nested tabular environment:

X & Y \\
\begin{tabular}[t]{@{}l@{}}A \\ B \end{tabular} & \lipsum[1] \

Of course it's better to define a personal command for this:

\newcommand{\breakcell}[2][l]{\begin{tabular}[t]{@{}#1@{}}#2\end{tabular}}

so that the input can become

X & Y \\
\breakcell{A \\ B} & \lipsum[1] \

With this definition, \breakcell can also be called as \breakcell[c]{...} or \breakcell[r]{...} to change the inner horizontal alignment.

Related Question