I want to vertically align text to the top of every cell, in a tabular
environment where some cells must span multiple rows.
Try not to use other packages if possible. (I've no control over installation of additional packages.)
\documentclass[12pt, margin = 1mm]{standalone}
\newcommand\TS{\rule{0pt}{2.6ex}} % Top strut
\newcommand\BS{\rule[-0.9ex]{0pt}{0pt}} % Bottom strut
\usepackage{array, multirow}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\TS\BS\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering \let\newline\\\TS\BS\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft \let\newline\\\TS\BS\arraybackslash}p{#1}}
\begin{document}
\begin{tabular} [t] { C{2cm} C{3cm} | C{2cm} C{3cm} }
Column 1 & Column 2 & Column 3 & Column 4 \\ \hline
Foo & Line 1 \newline Line 2 &
\multirow{2}{*}{Alpha} & Line 1 \newline Line 2 \newline Line 3 \\
Bar & Line 1 \newline Line 2 \\
Spam & Line 1 \newline Line 2 &
\multirow{2}{*}{Beta} & Line 1 \newline Line 2 \newline Line 3 \\
Eggs & Line 1 \newline Line 2 \\
\end{tabular}
\end{document}
There are two problems:
-
Using
p{#1}
instead ofm{#1}
helps to align Foo, Bar, Spam, Eggs to the top, but not Alpha, Beta. The[t]
argument didn't work. -
Alpha and its 3 lines do not span the rows of Foo, Bar. Likewise for Beta.
How can we solve both problems?
Best Answer
like this?
without
multirow
, with simplified types of columns definitions and with use ofmakecell
:edit (1): or you looking for for simple table:
which has slightly different vertical spacing:
edit(2): solution with
multirow
(as op so much desire, however which/how many rows should span is unfortunately no clear to me)the result is is look the same as before (in edit (1)) if only one word is in
multirow
s cell. in case that there are more, for example as:the result is: