118

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.

David Carlisle
  • 757,742
celenius
  • 5,274

11 Answers11

107

use

\rule{0pt}{4ex}    

in the first column of that line.

  • 11
    This does work (thank you). It creates a small offset unless the cell contents are touching the code (no whitespace). – celenius Apr 01 '12 at 16:41
  • Ignore my previous message, this worked for me. +1 – Caleb Stanford Feb 06 '20 at 15:43
  • 1
    Can you please explain the arguments? – Nagabhushan S N Apr 08 '20 at 09: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 '21 at 10:04
  • Update: it's to the left of your cell's text, not above (the horizontal line height starts at the same baseline as the text). – Rusca8 Mar 23 '21 at 10:26
  • 6
    btw, you can add space under the text by changing the \\ ending to \\[4ex] – Rusca8 Mar 23 '21 at 10:29
  • Completely novel workaround! – kurtkim Jan 25 '24 at 12:55
61

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

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
Mico
  • 506,678
  • 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 04: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 08:55
  • +1 for bottom strut. why is the syntax different? – flies May 06 '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 06 '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 http://en.wikibooks.org/wiki/LaTeX/Rules_and_Struts part 2 http://en.wikibooks.org/wiki/LaTeX/Boxes#TeX_character_boxes – flies May 07 '14 at 16:23
  • It's worth noting that if this appears with \frac or similar commands, then the \T and \B will need to go into the numerator part of \frac or the denominator. – Joel Nov 08 '17 at 20:09
  • @Joel - Thanks. The top and bottom struts defined in my answer are definitely set up with a working assumption that they'll be employed in a line of text (with uppercase and lowercase letters). If one has a \frac or (worse!) \dfrac term in a given row, it'll definitely be essential to place the top- and bottom-struts in the numerator and denominator parts, respectively. :-) – Mico Nov 08 '17 at 20:38
21

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

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.

David Carlisle
  • 757,742
12

use

    \addlinespace[2ex]

in the beginning of a line.

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

Johannes
  • 121
  • 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 00:39
3

fwiw, https://texfaq.org/FAQ-struttab summarises all the above, and mentions a couple of other packages. (apologies for intruding with an obvious pointer.)

David Carlisle
  • 757,742
wasteofspace
  • 5,352
3

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!

mcp
  • 229
  • 2
  • 9
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.

hrbjoern
  • 401
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

L.J.R.
  • 10,932
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.

Rick F
  • 1
-3

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

TeXnician
  • 33,589
adam
  • 1
  • 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 07 '17 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 07 '17 at 13:28