70

Is there a way that I can insert a small space in a table? When I use a superscript, the number touches the \hline.

\documentclass[9pt,letterpaper]{article}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\begin{picture}(0,0)

\put(20,-136){\mbox{    
        \footnotesize   
        \begin{tabular}{ p{8em}  r  r  l }  
        \hline      
                        & Total     & Average   & Unit   \\
        \hline      
        Area1           & 419773    &   9.15        &  \emph{m$^2$}      \\      
        Area2           & 0     &   0       &  \emph{m$^3$}      \\
        \hline  
        \end{tabular}
    }}  

\end{picture}

\end{document}

I tried inserting \vspace but this does not move everything, just one cell.

\vspace{0.001 in} Area1 & \vspace{0.001 in} 419773  &   \vspace{0.001 in} 9.15      & \vspace{0.001 in} \emph{m$^2$} \

My preference would be to adjust this without an external package, as I am using an old version of LaTeX on a server that I cannot replace.

63

use

\rule{0pt}{4ex}    

in the first column of that line.

  • 6
    This does work (thank you). It creates a small offset unless the cell contents are touching the code (no whitespace). – celenius Apr 1 '12 at 16:41
44

For a general reference on how to improve the spacing in tabular and array lines, see the article "Correct spacing for tables and arrays" by Claudio Beccari on p. 10 of TeX and TUG News 1993 (Vol. 2, No. 3).

His method, which involves judiciously inserting "struts", applies to lines in tabular (as well as tabular*, supertabular, xtabular, longtable) and array environments which contain

  • superscript material, on a line that's preceded by an \hline,
  • subscript material, on a line that's followed by an \hline, and
  • any other lines with material (including \hlines) above or below them that might result in a cramped look of the output.

He suggested defining a "top strut" and a "bottom strut" as follows:

\newcommand\T{\rule{0pt}{2.6ex}}       % Top strut
\newcommand\B{\rule[-1.2ex]{0pt}{0pt}} % Bottom strut

Using your MWE as a starting point -- by the way, 9pt is not a recognized option in the article document class, so I'm omitting it -- one could put these macros to use as follows:

\documentclass[letterpaper]{article}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

\newcommand\T{\rule{0pt}{2.6ex}}       % Top strut
\newcommand\B{\rule[-1.2ex]{0pt}{0pt}} % Bottom strut

\begin{document}  
\begin{tabular}{ p{8em}  r  r  l }  
\hline      
          & Total     & Average   & Unit \T\B  \\    \hline      
Area 1    & 419773    &   9.15    &  m\textsuperscript{2} \T \\      
Volume 1  & 0         &      0    &  m\textsuperscript{3} \B \\    \hline  
\end{tabular}

\end{document}

enter image description here

  • 1
    This is a very nice approach. Is there a particular reason for putting the struts at the end of the line? That does add a very small padding for me (or maybe I am doing it wrong?) – XXX Mar 19 '14 at 4:18
  • 2
    @Boris - the struts can be inserted anywhere in a given row; I simply find it easiest to read the code if they're inserted at the start of the left-most cell or the end of right-most cell. There should be no extra (horizontal) padding from the struts; what you observe on the MWE is LateX's insertion of whitespace in the amount of \tabcolsep. – Mico Mar 19 '14 at 8:55
  • +1 for bottom strut. why is the syntax different? – flies May 6 '14 at 15:06
  • 2
    @flies - Thanks. I'm not sure I understand what you mean by the syntax being different. Are you referring to the way the macros \T and \B are defined? A LaTeX \rule has one optional argument -- its depth, given in square brackets; a non-negative length parameter that indicates how much it protrudes below the baseline; if not provided, the default value of 0pt is used -- and two mandatory arguments: the rule's width (0pt in both cases since we're creating "invisible" rules) and the rule's height above the baseline. The height is nonzero for a top strut and zero for a bottom strut. – Mico May 6 '14 at 15:23
  • 1
    I was asking about the square brackets in ignorance of the difference between depth and height. It looks like my question is also answered in the latex wikibook: part 1 en.wikibooks.org/wiki/LaTeX/Rules_and_Struts part 2 en.wikibooks.org/wiki/LaTeX/Boxes#TeX_character_boxes – flies May 7 '14 at 16:23
12

you can load array package then

\setlength\extrarowheight{3pt}

the array package is a required part of the core latex distribution, so will be available on all installations.

12

The simplest solution was given by David Carlisle in How to add vertical space struts after hline?

\hline
\noalign{\vskip 2mm}    

For those who can use the bigstrut package, then just inserting \bigstrut[t] will fix the problem.

\documentclass[letterpaper]{article}
\usepackage{helvet}
\usepackage{bigstrut}
\renewcommand{\familydefault}{\sfdefault}

\begin{document}
\begin{picture}(0,0)

\put(20,-136){\mbox{    
        \footnotesize   
        \begin{tabular}{ p{8em}  r  r  l }  
        \hline      
                        & Total     & Average   & Unit   \\
        \hline      
        Area1           & 419773    &   9.15        &  \emph{m$^2$} \bigstrut[t]     \\  
        Area2           & 0     &   0       &  \emph{m$^3$}      \\
        \hline  
        \end{tabular}
    }}  

\end{picture}

\end{document}
6

use

    \addlinespace[2ex]

in the beginning of a line.

Of the booktabs package (which you want to use anyway to polish up your tables).

  • 2
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Could you please show how to use this in the MWE code that the question contains. It would be easier to understand for everybody what exactly to do, and also easier to check how the result looks like :) Thanks! – yo' Mar 14 '15 at 19:48
  • Thank you! This is the only solution that worked for me! – Veridian Jan 29 '17 at 0:39
3

fwiw, http://www.tex.ac.uk/cgi-bin/texfaq2html?label=struttab summarises all the above, and mentions a couple of other packages. (apologies for intruding with an obvious pointer.)

0

It may be worthwhile to take a look at the "booktabs" package, http://www.ctan.org/pkg/booktabs. Then, using e.g. the command \midrule instead of \hline provides additional space between the columns.

-3

\rule{0pt}{4ex}} x&x\\ \;x&x\\ \;x&x\\

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Could you explain a bit more your answer? – CarLaTeX Mar 7 '17 at 13:18
  • It's not clear to me how this goes beyond Herbert's answer and what the } x&x\ \;x&x\ \;x&x` will achieve, it looks like this has an unmatched }` which could cause trouble. – Dai Bowen Mar 7 '17 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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