We've already covered how to deal with the row height in latex, but what if you want to make only certain rows separated. When designing a table with multiple lines per cell we will use the \hline structure to make the table seem like it has multiple rows.
In this case we need to separate the rows individually, which can be done at the end of the tabular line. Consider the following code:
\begin{tabular}{rl}
{\bf First Column} & {\bf Second Column} \\\hline \\ [-1.5ex]
First Item & First Attribute \\
& Second Attribute \\
& Third Attribute \\ [1ex] \hline \\ [-1.5ex]
Second Item & First Attribute \\
& Second Attribute \\
& Third Attribute \\
& Fourth Attribute \\ [1ex] \hline \\ [-1.5ex]
Third Item & First Attribute \\
& Second Attribute \\ [1ex] \hline \\ [-1.5ex]
Fourth Item & First Attribute \\
& Second Attribute \\
& Third Attribute \\ [1ex] \hline \\ [-1.5ex]
\end{tabular}
Putting [1ex] at the end of a line creates that much extra space after the line. The idea here is to make 1ex before the \hline, and then put a completely blank line after it. the [-1.5ex] moves the line after the \hline up, making the gap less than a full line. The result is in the following image:
Sunday, May 17, 2009
Subscribe to:
Post Comments (Atom)
Excellent! I've been looking for how to do this for ages. Thanks very much
ReplyDeleteGood trick. The only thing is that it doesn't look good with vertical lines.
ReplyDeleteWorks great for me. Thanks.
ReplyDeleteJust what i needed too. It works well with vertical lines too, if you add enough '&'s along with the '\\'. Thank you!
ReplyDeleteThe booktabs package is also perfect for this kind of considerations. It handles space above and below lines very well and provides the keywords toprule, midrule, and bottomrule which make your code more declarative.
ReplyDeleteThanks a lot!
ReplyDeletevery useful. thanks
ReplyDeletehorrible with vertical lines
ReplyDeleteThanks master :)
ReplyDeleteV V useful, thanks a lot!
ReplyDeleteHi! Have you ever noticed, has your writting style gone any better lately?
ReplyDeleteThanks a lot :)) It's really beneficial.
ReplyDelete\renewcommand{\arraystretch}{1.5}
ReplyDelete\begin{tabular}
....
\end{tabular}
this works better
Just use booktabs and be done with it.
ReplyDeleteYou're the man
ReplyDelete