tags:

views:

4823

answers:

5

How do you add spacing after an \hline in a tabular? I can add spacing before it using \vspace, however if I try to add spacing after the \hline, the spacing will come after the next line of text. Here is what I have so far:

\multicolumn{2}{Hello!} \vspace{4pt} \\
\hline \textit{Hi!} & \textit{Ho!}

I don't want to add a line break after the \hline and do something like \vspace{-xxpt} or use \rule because the generated HTML document from Hevea will be ugly.

A: 

Not sure whether this works inside tabular environments, but you could try a \minipage around the \hline:

\begin{minipage}{ <width> }
... \hline \vspace{4pt}
\end{minipage}
Frank Grimm
+3  A: 

Create a new row with \hline and trim it with negative spacing

\multicolumn{2}{c}{Hello!} \\

\hline \\ [-1.5ex]

\textit{Hi!} & \textit{Ho!}

M456
I also used %BEGIN LATEX ... %END LATEX to exclude the '\\' from the generated HTML as suggested by Jouni K. Seppänen below.
verhogen
+3  A: 

If you are concerned about output from some other program than TeX, the right approach would be to define a higher-level command or environment to do what you want, use whatever dirty hacks inside the definitions to make the TeX output look good, and define its HTML meaning separately (I don't know how to do this in Hevea, but I imagine any reasonable TeX processor would have this kind of facility).

Perhaps this has already been solved for you: does e.g. booktabs produce the kind of tables in LaTeX that you like? Does Hevea handle booktabs commands nicely? If booktabs doesn't do what you want, its source code might be interesting to look at - it's all about setting the widths and spaces of lines so that the tables look presentable.

Jouni K. Seppänen
Good point in the first paragraph. Prompted me to look into Hevea documentation instead of looking at Latex documentation.
verhogen
+2  A: 

I think that your problem is that the vertical lineskip in tables is not big enough when hlines are between each row. The solution is to add

\usepackage{tabularx}

\setlength{\extrarowheight}{3pt}

into your preamble.

Svante
A: 

While trying to answer this question for myself, I came across the following hack from https://www.msu.edu/~harris41/latex_tablespacing.html

I was using the solution mentioned above by M456, but this does not play nicely with vertical rules in the tabular environment, and so I think this is a bad choice as a default solution (generally I don't include vertical rules, but one of my tables really needed them for clarity).

The idea is to define a strut which should be included in one of the cells for a row which is either immediately before or after an hline. i.e.

in preamble:
\newcommand\tstrut{\rule{0pt}{2.4ex}}
\newcommand\bstrut{\rule[-1.0ex]{0pt}{0pt}}

\begin{tabular}{ccc}
\hline\hline
Head 1 & Head 2 & Head 3 \tstrut \bstrut \\
\hline
a1 & a2 & a3 \tstrut \\
b1 & b2 & b3 \\
c1 & c2 & c3 \\
d1 & d2 & d3 \bstrut \\
\hline\hline
\end{tabular}

(I adjusted the strut size somewhat from the web page - adjust it to suit your taste)

There may be better ways to do this, but this seems clean enough, and is easily customisable.

Nathan