17

The tabular environment does not add any vertical space before or after it. This looks odd, in my view. What is the "correct" or "best" way to add some space? Also, why is there more space after the tabular environment than before it, as seen in the example below?

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

\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

  • 2
    Adding a \vspace command before and after works. – Faheem Mitha Mar 7 '16 at 19:28
6

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

  • I notice it's necessary (as you do) to add less extra space after the table than before it to make the spaces appear similar. I still find that kind of odd and random. – Sverre Nov 1 '13 at 12:18
  • @Sverre, it is because of the descenders "g" hanging below the line. I think if there were no descenders in the table, the added space would be symmetric – Steven B. Segletes Nov 1 '13 at 12:20
  • Actually no. The table originally said "Word", and I noticed the larger gap below the table. I added the "g" to test if it was due to the height of the "W". But when I added the "g", it just pushed the text below the table even further down. – Sverre Nov 1 '13 at 12:29
  • @Sverre. Both descenders in the line prior to the table, as well as descenders in the last line of the table will shift the table's position. Capital letters in the table will have no effect. One way to combat this contrariness is to add a \strut after the it. prior to the table, and add a \strut to the last entry in the table. Then, the added buffer will end up symmetric. – Steven B. Segletes Nov 1 '13 at 12:41
  • I don't understand the added side note in your answer. Aren't [12pt 8pt] which you added "actual lengths"? – Sverre Nov 1 '13 at 12:46
11

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… :-) .

  • A two year old question, yes, but that doesn't mean new and useful answers can't be added :) – Sverre Apr 1 '16 at 9:07
3

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}
  • Right - I changed every character in the document with 'a', and now the spaces look identical. – Sverre Nov 1 '13 at 12:33
  • the text line above the tabular has no descenders. add a strut at the end of that sentence. – barbara beeton Nov 2 '13 at 2:00
-1

Another possibility is to use \\ as presented next.

\noindent Here is a line with some text in it. 
\\

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

\noindent Here is another line with some text in it.
  • 4
    Oh, no, please: don’t do that! – GuM Mar 31 '16 at 21:43

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.