Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I wanted to put a bit of space after an \hline in an array; the main suggestion floating round the Internet seems to be to use

\hline \\ [-1.5ex]

Unfortunately, this causes a gap in the line on the RHS of the array. A minimal example is:

\documentclass{article}
\begin{document}
$\begin{array}{|l|l|}%
\hline
& TEXT\\
\hline \\[-1.5ex]
&TEXT
\\\hline
\end{array}$
\end{document}

enter image description here

Any help would be much appreciated!

share|improve this question
    
What are you after? Reducing the gap between lines in your array or increasing it? –  Werner Jul 29 '12 at 13:21
    
Increasing it. The -1.5ex is just because a full line is too much white space. The method is from stackoverflow.com/questions/696157/latex-hline-spacing . –  Mohan Jul 30 '12 at 23:33
    
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). –  Werner Aug 1 '12 at 17:46

2 Answers 2

up vote 6 down vote accepted

Rather than fiddling with \hline, it's better in your case to provide "struts": either a "top strut," which provides vertical spacing above the line where it's placed, or a "bottom strut," which provides vertical spacing below the line where it's placed. This idea is not original to me -- it goes back (at least) to an article published by Claudio Beccari in TeX and TUG News in 1993. What's nifty about this is that one can place both a top strut and and bottom strut on a given line of an array or tabular environment.

The following MWE shows how this might be done. Note that I've switched from array to tabular in order to strip things down to a bare minimum; the vertical spacing issues related to \hline are the same for both environments.

\documentclass{article}

% define "struts", as suggested by Claudio Beccari in
%    a piece in TeX and TUG News, Vol. 2, 1993.
\newcommand\Tstrut{\rule{0pt}{2.6ex}}         % = `top' strut
\newcommand\Bstrut{\rule[-0.9ex]{0pt}{0pt}}   % = `bottom' strut

\begin{document}
First \emph{with} struts:

\smallskip
\begin{tabular}{|l|}
\hline
TEXT\Tstrut\Bstrut\\ % top *and* bottom struts
\hline
TEXT \Tstrut\\       % top strut only
TEXT \Bstrut\\       % bottom strut only
\hline
\end{tabular}

\bigskip
And now \emph{without} struts (the default):

\begin{tabular}{|l|}
\hline
TEXT\\ 
\hline
TEXT\\    
TEXT\\      
\hline
\end{tabular}
\end{document}

enter image description here

share|improve this answer
    
Thanks! I've left some related comments on Werner's post... –  Mohan Jul 30 '12 at 23:31
    
@Mohan - You mention (in a comment left on Werner's answer) that your tabular environments are generated by some program (Stata, maybe?). If so, can't you set up the program to insert a \Tstrut instruction (rather than something like \\[1ex], say) automatically after every \hline? Just a thought. –  Mico Jul 31 '12 at 0:25
    
The arrays are generated by some Haskell code I've written. It's not inserting the strut commands that's tricky... it's the fact that the heights of entries might vary. Unless I've misunderstood something, if a particular entry is taller than a Tstrut, the strut will have no effect. Is that right? –  Mohan Jul 31 '12 at 11:37
    
@Mohan - It depends where the \Tstrut instruction is inserted. If it's inserted on the baseline, you're correct in assuming that it won't have an effect on stuff that's tall than Tstrut. Assuming that what's being typeset is some mathematical expression with superscripts, could you modify the Haskell code to insert a \Tstrut inside the superscript's argument? –  Mico Jul 31 '12 at 11:45
    
thanks again for all the advice! It's not in fact, a superscript; it's a representation used in linguistics, and you can have tables nested inside tables (to arbitrary depth). But when I was playing around I found that the padding I'm putting around tables can be made sufficient to distance nested tables from the hline, which is good enough. Thanks for all the help! (Just in case you're interested, the result is at s14.postimage.org/5cy6abt7j/derivation_images_80.png .) –  Mohan Jul 31 '12 at 21:10

On a case-by-case basis you can insert a vertical strut (zero-width, vertical rule/object) to push the row contents away from others. Here's a small example:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\[
  \begin{array}{|l|l|}%
    \hline
    & \text{Text} \\
    \hline
    \rule{0pt}{1.5\normalbaselineskip} & \text{Text} \\
    \hline
  \end{array}
\]
\end{document}

I've inserted a vertical strut of height 1.5\normalbaselineskip which is 18pt in the above example, any length exceeding the about 70% of the baseline skip would work. For more information on column and/row padding, see Column padding in tables.

Note that I've used amsmath to supply the \text command for setting text in math mode. Even though this is just a simple example and using \mbox would also suffice, amsmath also provides other functionality that is well worth using.


If you wish to insert a fixed amount (say) <len> between two rows, you can insert a blank row (with the appropriate number of column alignments & to provide correct vertical rule placement) and use a row skip of the form \\[\dimexpr-\normalbaselineskip+<len>]. This would jump "back" a length of \normalbaselineskip - the baseline distance between rows - and jump "forward" by <len> - the required gap. Here's a small example:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\[
  \begin{array}[t]{|l|l|}%
    \hline
    & \text{Normal} \\
    \hline
    & \text{Text} \\
    \hline
  \end{array} \quad
  \begin{array}[t]{|l|l|}%
    \hline
    & \texttt{0pt} \\
    \hline
    & \\[-\normalbaselineskip]
    & \text{Text} \\
    \hline
  \end{array} \quad
  \begin{array}[t]{|l|l|}%
    \hline
    & \texttt{2pt} \\
    \hline
    & \\[\dimexpr-\normalbaselineskip+2pt]
    & \text{Text} \\
    \hline
  \end{array} \quad
  \begin{array}[t]{|l|l|}%
    \hline
    & \texttt{1em} \\
    \hline
    & \\[\dimexpr-\normalbaselineskip+1em]
    & \text{Text} \\
    \hline
  \end{array} \quad
  \begin{array}[t]{|l|l|}%
    \hline
    & \texttt{3pc} \\
    \hline
    & \\[\dimexpr-\normalbaselineskip+3pc]
    & \text{Text} \\
    \hline
  \end{array}
\]
\end{document}
share|improve this answer
    
Thanks! There is one difficulty with this approach, which is that I'm automatically generating my LaTeX code in a program. So I can't tune the height on a case-by-case basis. I will experiment with putting in a constant-height strut, but what I really want to do is put a fixed amount of space between the hline and whatever comes after it, regardless of the height of the latter. Maybe I can wrap whatever comes after the hline in some kind of vertical box, with a strut placed above it? It's a bit fiddly, but it would probably work... –  Mohan Jul 30 '12 at 23:28
    
@Mohan: I've updated my answer with a possibility that might work for you. Give some feedback if it doesn't. –  Werner Aug 1 '12 at 15:16
    
"with the appropriate number of column alignments & to provide correct vertical rule placement" --- ah! That's what I was missing. Thank you very much. (Output is now also satisfactory, though I used other means.) –  Mohan Aug 1 '12 at 17:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.