107

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.

4

11 Answers 11

98

use

\rule{0pt}{4ex}    

in the first column of that line.

6
  • 11
    This does work (thank you). It creates a small offset unless the cell contents are touching the code (no whitespace).
    – celenius
    Apr 1, 2012 at 16:41
  • Ignore my previous message, this worked for me. +1
    – 6005
    Feb 6, 2020 at 15:43
  • Can you please explain the arguments? Apr 8, 2020 at 9:50
  • 2
    @NagabhushanSN as far as I understand, it's creating a horizontal line of length 0 above your cell's text (doesn't show up because it can't stretch to the right, but takes up the space anyway). The 0pt is the length to the right, the 4ex is the height (4ex is 4 times the height of a lowercase x, so you can make it thinner by changing that 4).
    – Rusca8
    Mar 23, 2021 at 10:04
  • 2
    btw, you can add space under the text by changing the \\ ending to \\[4ex]
    – Rusca8
    Mar 23, 2021 at 10:29
57

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

7
  • 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, 2014 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, 2014 at 8:55
  • +1 for bottom strut. why is the syntax different?
    – flies
    May 6, 2014 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, 2014 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, 2014 at 16:23
20

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}
14

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.

0
9

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
  • 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, 2015 at 19:48
  • Thank you! This is the only solution that worked for me!
    – Veridian
    Jan 29, 2017 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.)

1
1

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.

1

It’s easy to set rowsep with tblr environment of the new LaTeX3 package tabularray:

\documentclass[9pt,letterpaper]{article}

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

\usepackage{tabularray}
\SetTblrInner{rowsep=2pt}

\begin{document}

\begin{picture}(0,0)
\put(20,-136){\mbox{    
        \footnotesize   
        \begin{tblr}{ 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{tblr}
    }}  
\end{picture}

\end{document}

enter image description here

0

I found a cool solution for putting spaces inside a table. Simply add a row containing \vspace{-0.3cm}\. This will add a row to the table and then back up the spacing by 0.3cm or whatever you want.

0

David's answer, made relevant by Scott Prahl, is the winner for no-dependency simplicity. Because I don't want to control the spacing, I like Christian's similar answer, which becomes:

\hline \noalign{\smallskip}

In some cases this looks better:

\noalign{\smallskip} \hline \noalign{\smallskip}

Either of which can be stored in a command:

\newcommand{\eqline}{\noalign{\smallskip} \hline \noalign{\smallskip}}

Explanation of why \noalign{} is needed welcome!

4
  • This helped me with adding a horizontal line to an equation. Feb 27 at 20:21
  • 1
    This seems better-suited as a comment as you're merely taking content from existing answers and elaborating on them. Would you agree?
    – Werner
    Feb 27 at 23:05
  • Yea I'd agree, and went to do that first, but the space and formatting limitations of the comment don't support it as well. Feb 28 at 1:48
  • Also, similar to Scott's answer, my answer comes from a post outside this thread. Feb 28 at 1:50
-3

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

2
  • 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, 2017 at 13:18
  • 1
    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, 2017 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.