8

This is, in a way, a follow-up-question to New table-environment, spaces and enclosing { } in a new environment, which has already been answered conveniently by @egreg.


Please compile this MWE to see and follow the problem:

\documentclass[a4paper, 11pt]{scrbook}
\usepackage{blindtext}
\usepackage[cm]{fullpage}

\usepackage{tabu, longtable, booktabs}
\usepackage{caption}

\newenvironment{texttab}[1]%
        {\setlength{\topsep}{\baselineskip}%
            \begin{center} \tabulinesep=0.6ex%
            \begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
            {\end{tabu}%
        \end{center}}

\newenvironment{tabspaces}[1]%
    {\setlength{\topsep}{\baselineskip}%
        \begin{center} \tabulinesep=0.6ex%
            \begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
            {\end{longtabu}%
        \end{center}}

\newenvironment{texttab*}[1]%
    {\setlength{\topsep}{\baselineskip}%
    \LTpre=0pt%
    \LTpost=0pt%
        \begin{center} \tabulinesep=0.6ex%
            \begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
            {\end{longtabu}%
        \end{center}}

\begin{document}
\section{TEST}
\blindtext
%
\begin{texttab}{X[l,2] X[l,2] X[l,3]}
Test1   &   Test2   &   Test3 works fine  \\ \midrule
Test1   &   Test2   &   Test3 works fine  \\
Test1   &   Test2   &   Test3 works fine  \\ \bottomrule
\end{texttab}%
%
\blindtext
%
\begin{tabspaces}{X[l,2] X[l,2] X[l,3]}
Test1   &   Test2   &   Test3   \\ \midrule
Test1   &   Test2   &   Test3   \\
Test1   &   Test2   &   Test3   \\ \bottomrule
\end{tabspaces}%
%
\blindtext
%
\begin{texttab*}{X[l,2] X[l,2] X[l,3]}
Test1   &   Test2   &   Test3   \\ \midrule
Test1   &   Test2   &   Test3   \\
Test1   &   Test2   &   Test3   \\ \bottomrule
\end{texttab*}%
%
\blindtext
\end{document}

I created three new environments: texttab, tabspaces and texttab*. They implement tabus (not to be embedded in floating bodies) in the text. As a result of the question mentioned before I made two environments for either normal tabus (texttab) or longtabus (texttab*). tabspaces is just for demonstration-use.

Now, if you take a look at the tabspaces-environment (second table in the example), you see it produces way too much vertical space above and below the environment.

I tried to use the commands \LTpre=0pt and \LTpost=0pt(provided by the longtable-package) in the texttab*-environment - you see, there's still way too much space below!

Where does it come from and how do I get rid of it?

Note: \tabulinesep=0.6ex seems to affect those spaces! Nevertheless, removing it doesn't change the fact that the vertical spaces still differ from the ones in my (satisfying) texttab-environment.

1 Answer 1

7

The reason why setting \LTpre and \LTpost has no effect on the texttab* environment is because you reset them to 0pt in the definition of that environment. I removed those two lines and set some rough values globally that give similar spacing to that produced by texttab.

enter image description here

\documentclass[a4paper, 11pt]{scrbook}
\usepackage{blindtext}
\usepackage[cm]{fullpage}

\usepackage{tabu, longtable, booktabs}
\usepackage{caption}
\setlength{\LTpre}{0pt}\setlength{\LTpost}{-17pt}%

\newenvironment{texttab}[1]%
        {\setlength{\topsep}{\baselineskip}%
            \begin{center} \tabulinesep=0.6ex%
            \begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
            {\end{tabu}%
        \end{center}}

\newenvironment{tabspaces}[1]%
    {\setlength{\topsep}{\baselineskip}%
        \begin{center} \tabulinesep=0.6ex%
            \begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
            {\end{longtabu}%
        \end{center}}

\newenvironment{texttab*}[1]%
    {\setlength{\topsep}{\baselineskip}%
        \begin{center} \tabulinesep=0.6ex%
            \begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
            {\end{longtabu}%
        \end{center}}

\begin{document}
\section{TEST}
\blindtext
%
\begin{texttab}{X[l,2] X[l,2] X[l,3]}
Test1   &   Test2   &   Test3 works fine  \\ \midrule
Test1   &   Test2   &   Test3 works fine  \\
Test1   &   Test2   &   Test3 works fine  \\ \bottomrule
\end{texttab}%
%
\blindtext
%
\begin{tabspaces}{X[l,2] X[l,2] X[l,3]}
Test1   &   Test2   &   Test3   \\ \midrule
Test1   &   Test2   &   Test3   \\
Test1   &   Test2   &   Test3   \\ \bottomrule
\end{tabspaces}%
%
\blindtext
%
\begin{texttab*}{X[l,2] X[l,2] X[l,3]}
Test1   &   Test2   &   Test3   \\ \midrule
Test1   &   Test2   &   Test3   \\
Test1   &   Test2   &   Test3   \\ \bottomrule
\end{texttab*}%
%
\blindtext
\end{document}

Qrrbrbirlbel points out below that using \centering rather than the center environment is an option. My quick attempt is below. I did a bit of fiddling with \par's to avoid the lines above from being centered as well...I'm not sure if there's a better way to go about doing that. In any case, because of the different behaviour of tabu and longtabu I think you may have to fiddle with the spacing of the first environment to match the latter two or vice-versa.

\documentclass[a4paper, 11pt]{scrbook}
\usepackage{blindtext}
\usepackage[cm]{fullpage}

\usepackage{tabu, longtable, booktabs}
\usepackage{caption}

\newenvironment{texttab}[1]%
    {\par\bigskip\centering\tabulinesep=0.6ex%
     \begin{tabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
    {\end{tabu}\par\bigskip}

\newenvironment{tabspaces}[1]%
    {\par\centering\tabulinesep=0.6ex%
     \begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
    {\end{longtabu}}

\newenvironment{texttab*}[1]%
    {\par\centering\tabulinesep=0.6ex%
     \begin{longtabu} to 0.9\textwidth {#1} \toprule \rowfont{\bfseries}}
    {\end{longtabu}}

\begin{document}
\section{TEST}
\blindtext

\begin{texttab}{X[l,2] X[l,2] X[l,3]}
Test1   &   Test2   &   Test3 works fine  \\ \midrule
Test1   &   Test2   &   Test3 works fine  \\
Test1   &   Test2   &   Test3 works fine  \\ \bottomrule
\end{texttab}%

\blindtext
%
\begin{tabspaces}{X[l,2] X[l,2] X[l,3]}
Test1   &   Test2   &   Test3   \\ \midrule
Test1   &   Test2   &   Test3   \\
Test1   &   Test2   &   Test3   \\ \bottomrule
\end{tabspaces}%
%
\blindtext
%
\begin{texttab*}{X[l,2] X[l,2] X[l,3]}
Test1   &   Test2   &   Test3   \\ \midrule
Test1   &   Test2   &   Test3   \\
Test1   &   Test2   &   Test3   \\ \bottomrule
\end{texttab*}%
%
\blindtext
\end{document}
7
  • Hello and thank you very much! There remains a little question, though: How is it that one has to set '\LTpost=-17pt'? Why isn't "=0pt" that eliminates all space and, furthermore, how did you figure out it should be '-17pt' to serve its purpose? Thank you in advance!
    – LCsa
    Jun 11, 2013 at 20:05
  • No problem! Unfortunately, I don't know what specifically it is about longtabu/longtable that causes the extra spacing. I assume that it is a consequence of the ability to split a table across pages. The -17pt was simply from guess and check...I tried -15pt and it wasn't enough while -20pt was too much. I'm not sure if it's exact, but it looked close enough to me.
    – Scott H.
    Jun 11, 2013 at 20:29
  • Haha, I see - and thought so, because I tried to check all possible lengths and heights with 'printlen' and so forth... :P Maybe I'll find a way to work "exact", you know what I mean. But until then, I'm glad you came up with your answer (which is now accepted). :)
    – LCsa
    Jun 11, 2013 at 20:46
  • 1
    I don’t exactly know for what those length are, but it seems as if the combination with the center environment introduces one empty line (besides the usual vertical space from the center environment). Setting the post length to -\baselineskip produces a satisfying result (IMO). Maybe it is better to not use the center environment and the macro \centering instead with properly set pre and post lengths? Jun 11, 2013 at 22:01
  • @Qrrbrbirlbel That's a good suggestion, I didn't consider that the center environment might have something to do with it. Would you like to add an answer or should I update mine to include that option?
    – Scott H.
    Jun 12, 2013 at 4:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .