[Tex/LaTex] longtable vertical space

longtabletables

If I make longtable, how can I remove the spacing between preceding text and it? Tabular doesn't have this spacing.

This example should make clear to you what I'm asking:

\documentclass[a4paper]{article}
\usepackage[margin = 5mm]{geometry}
\usepackage{longtable}
\begin{document}
\centering
Can you see how little vertical space there is between this line and the table down here \ldots\\
\begin{tabular}{|c|c|c|c|}
        \hline
        0 & 1 & 2 & 3 \tabularnewline
        \hline
        4 & 5 & 6 & 7 \tabularnewline
        \hline
        8 & 9 & 0 & 1 \tabularnewline
        \hline
        2 & 3 & 4 & 5 \tabularnewline
        \hline
        6 & 7 & 8 & 9 \tabularnewline
        \hline
\end{tabular}\\
\vspace{3cm}
\ldots compared to this line and this table?\\
\begin{longtable}{|c|c|c|c|}
        \hline
        0 & 1 & 2 & 3 \tabularnewline
        \hline
        4 & 5 & 6 & 7 \tabularnewline
        \hline
        8 & 9 & 0 & 1 \tabularnewline
        \hline
        2 & 3 & 4 & 5 \tabularnewline
        \hline
        6 & 7 & 8 & 9 \tabularnewline
        \hline
\end{longtable}
\end{document}

Best Answer

tabular is an inline construct, like a big letter, so it does not have any spacing associated with it at all. longtable is a display construct like a displayed equation or a quote environment so always takes the full width of the page and is offset with vertical space. The space before is \LTpre which you can set to 0.

Avoid mis-using \\ at the end of a paragraph 9such as before longtable the bad effects of doing that are hidden here by a quirk of the \centering implementation, but normally it would produce an underfull box of badness 10000

enter image description here

\documentclass[a4paper]{article}
\usepackage[margin = 5mm]{geometry}
\usepackage{longtable}
\setlength\LTpre{0pt}

\begin{document}
\centering
Can you see how little vertical space there is between this line and the table down here \ldots

\begin{tabular}{|c|c|c|c|}
        \hline
        0 & 1 & 2 & 3 \tabularnewline
        \hline
        4 & 5 & 6 & 7 \tabularnewline
        \hline
        8 & 9 & 0 & 1 \tabularnewline
        \hline
        2 & 3 & 4 & 5 \tabularnewline
        \hline
        6 & 7 & 8 & 9 \tabularnewline
        \hline
\end{tabular}

\vspace{3cm}
\ldots compared to this line and this table?

\begin{longtable}{|c|c|c|c|}
        \hline
        0 & 1 & 2 & 3 \tabularnewline
        \hline
        4 & 5 & 6 & 7 \tabularnewline
        \hline
        8 & 9 & 0 & 1 \tabularnewline
        \hline
        2 & 3 & 4 & 5 \tabularnewline
        \hline
        6 & 7 & 8 & 9 \tabularnewline
        \hline
\end{longtable}
\end{document}
Related Question