Add space before and after tabular environment

The tabular environment simply puts its contents (after formatting them) inside a “box”, which is regarded by the surrounding context as it were a single, huge letter. In other words, typing

... the last words of the previous paragraph.

\begin{tabular}{*4{l}}
    Worg & Worg & Worg & Worg\\
    Worg & Worg & Worg & Worg\\
\end{tabular}

The first words of the following paragraph...

is logically equivalent to writing

... the last words of the previous paragraph.

X

The first words of the following paragraph...

That is, you get a paragraph by itself containing a single “box”: this box is the tabular environment in the first case and the letter “X” in the second.

This is done purposely: in this way, in theory you can place a tabular environment wherever a letter is allowed, that is, practically everywhere. The surrounding formatting should be supplied by the enclosing context.

I wouldn’t go for anything more complex than ordinary spacing commands, the same ones you would use to insert space between any two paragraphs. It is very common, too, to include tabular within a center environment, to have it centered between the text margins as well as separated by a convenient amount of vertical space from the preceding and following material.

Here is a simple example, complete and compilable:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[ascii]{inputenc}

\showboxbreadth = 100
\showboxdepth = 10



\begin{document}

\noindent A line with some text in it, but without indentation.

\begin{tabular}{*4{l}}
    Worg & Worg & Worg & Worg\\
    Worg & Worg & Worg & Worg\\
\end{tabular}

Here is another line with some text in it; this one, however,
\emph{is} indented.



\noindent A line with some text in it, but without indentation.

\medskip

\begin{tabular}{*4{l}}
    Worg & Worg & Worg & Worg\\
    Worg & Worg & Worg & Worg\\
\end{tabular}

\medskip

Here is another line with some text in it; this one, however,
\emph{is} indented.



Normally, one wants to center the \texttt{tabular} in addition to inserting 
space above and below:
\begin{center}
    \begin{tabular}{*4{l}}
        Worg & Worg & Worg & Worg\\
        Worg & Worg & Worg & Worg\\
    \end{tabular}
\end{center}
Text that follows.

% \showlists

\end{document}

If you uncomment the \showlists command, you will be able to check, in the transcript file, that the tabular is both preceded and followed by \lineskip glue: this is because, when used without a [b] or [t] optional argument, the tabular environment produces a box whose reference point is (more or less) vertically centered in the box itself. In our case, it turns out that this box has an height of 14.5pt and a depth of 9.5pt, that is, it behaves like an italic “f” with very tall ascender and very deep descender. When this happens, TeX’s normal line spacing is not applied.

Edit: Oops, I answered this question without noticing that it is more than two years old. It popped out at the top of the list of active questions just because of @EmanuelOliveira’s answer (which I do not recommend… :-) .


EDITED to provide two alternate approaches.

The verbatimbox package has a service routine \addvbuffer, in which the optional argument is one or two lengths (symmetric space or above/below space) to add around the contents:

\documentclass{article}
\usepackage{verbatimbox}
\begin{document}
\noindent Here is a line with some text in it.

\addvbuffer[12pt 8pt]{\begin{tabular}{*4{l}}
    Worg & Worg & Worg & Worg\\
    Worg & Worg & Worg & Worg\\
\end{tabular}}

\noindent Here is another line with some text in it.
\end{document}

enter image description here

If there are two lengths in the optional argument, they must be space separated. Thus, a valid optional argument involving two actual lengths would be, for example,

\addvbuffer[{2\baselineskip} \baselineskip]{...}  

The braces around the first length allow the following space to be expressed, which would otherwise be gobbled by the parser.

Note that with \addvbuffer, lengths can be negative (with some provisos).


If the gap will be limited to vertically symmetric [positive] additions, then the \addstackgap macro of the stackengine package will also suffice. In the MWE below, I also added a \strut to the end of the prior paragraph.

\documentclass{article}
\usepackage{stackengine}
\begin{document}
\noindent Here is a line with some text in it.\strut

\addstackgap[5pt]{\begin{tabular}{*4{l}}
    Worg & Worg & Worg & Worg\\
    Worg & Worg & Worg & Worg\\
\end{tabular}}

\noindent Here is another line with some text in it.
\end{document}

enter image description here


There is more space after the tabular then before as tabular inserts an invisible strut and the g goes less down then the W goes up:

\documentclass{article}
\begin{document}
\noindent Here is a line with some text in it.

xxxx\begin{tabular}{*4{l}}
    \rule[-\dp\strutbox]{0.4pt}{\dimexpr\ht\strutbox+\dp\strutbox}%shows the strut
    Worg & Worg & Worg & Worg\\
    Worg & Worg & Worg & Worg%
    \rule[-\dp\strutbox]{0.4pt}{\dimexpr\ht\strutbox+\dp\strutbox}\\    \end{tabular}

\noindent Here is another line with some text in it.
\end{document}

Tags:

Spacing

Tables