Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In the following MWE, one sees the difference between tabular and longtable, with respect to the vertical space before an itemize, inside a cell :

\documentclass[12pt]{article}
\usepackage{longtable,enumitem}
\begin{document}
\begin{longtable}{| p{3cm} |p{6cm}|}
\hline%
text &  
\begin{itemize}[topsep=0ex,partopsep=0ex]
\item Produkt und Quotient
\item Produkt und Quotient
\end{itemize}
\\ \hline 
\end{longtable}

\begin{tabular}{| p{3cm} |p{6cm}|}
\hline%
text &  
\begin{itemize}[topsep=0ex,partopsep=0ex]
\item Produkt und Quotient
\item Produkt und Quotient
\end{itemize}
\\ \hline 
\end{tabular}

\end{document}

What i would like, is to have in longtable the same vspace as in tabular. By the way, i set both topsep and partopsep to 0, just because i am ignorant, and i don't really know which one i should use...

share|improve this question
    
Maybe this answer is helpful: tex.stackexchange.com/questions/32425/… –  Marco Daniel Mar 3 '12 at 23:25

2 Answers 2

Oh! Sorry I think this is an unreported bug in longtable.

Longtable inserts a strut to keep a minimal separation between the text and any \hline or the previous row.

It does this with the following code

\def\LT@startpbox#1{%
  \bgroup
    \let\@footnotetext\LT@p@ftntext
    \setlength\hsize{#1}%
    \@arrayparboxrestore
    \vrule \@height \ht\@arstrutbox \@width \z@}

If you look at the equivalent code in the array package, you find

\def\@startpbox#1{\bgroup
%    \end{macrocode}
%    The argument is the width of the box. This information has to be
%    assigned to =\hsize=.
%    Then we assain default values to several parameters used in a
%    \textsf{parbox}.
% \changes{v2.3k}{1998/05/12}{Use \cs{setlength} to set \cs{hsize},
%      so that the calc package can be applied here (pr/2793)}
%    \begin{macrocode}
  \setlength\hsize{#1}\@arrayparboxrestore
%    \end{macrocode}
%    Our main problem is to obtain the same distance between succeeding
%    lines of the \textsf{parbox}.
%    We have to remember that the distance between two \textsf{parboxes}
%    should be defined by =\@arstrut=. That means that it can be
%    greater than the distance in a \textsf{parbox}.
%    Therefore it is not enough to set a =\@arstrut= at the
%    beginning and at the end of the \textsf{parbox}. This would
%    dimension the distance
%    between first and second line and the distance between the two
%    last lines of the \textsf{parbox} wrongly.
%    To prevent this we set an invisible rule of height
%    =\@arstrutbox=
%    at the beginning of the \textsf{parbox}. This has no effect on the
%    depth of the first line. At the end of the \textsf{parbox} we set
%    analogously another invisible rule which only affects the depth
%    of the last line. It is necessary to wait inserting this strut
%    until the paragraph actually starts to allow for things like
%    =\parindent= changes via =>{...}=.
% \changes{v2.1c}{1992/12/14}{Use `everypar to insert strut}
%    \begin{macrocode}
   \everypar{%
      \vrule \@height \ht\@arstrutbox \@width \z@
      \everypar{}}%
   }
%    \end{macrocode}
% \end{macro}

The important bit being the last few lines which delay adding the strut by using \everypar.

It seems to me the same fix should have been applied to longtable so only 20 years too late I suggest

\def\LT@startpbox#1{%
  \bgroup
    \let\@footnotetext\LT@p@ftntext
    \setlength\hsize{#1}%
    \@arrayparboxrestore
   \everypar{%
      \vrule \@height \ht\@arstrutbox \@width \z@
      \everypar{}}%
%    \vrule \@height \ht\@arstrutbox \@width \z@
}

which then makes both your tables have the same vertical spacing.

If you do this could you change

\ProvidesPackage{longtable}
          [2004/02/01 v4.11 Multi-page Table package (DPC)]

to

\ProvidesPackage{longtable}
          [2004/02/01 v4.11 Multi-page Table package (DPC) + strut fix]

I suspect after all this time I can't change longtables default spacing, however I should add an option to fix it.

share|improve this answer
    
I'm delighted to have found a 20-years-old bug ... and to get the fix by the original developer ! Thanks :) –  nicolas roy Mar 5 '12 at 7:28

Why don't you use a dedicated column type for this (originally posted by Donald Arseneau on c.t.t.), otherwise spacing is always a problem.

\documentclass[12pt]{article}
\usepackage{longtable,array,enumitem}
\makeatletter
%----  Enumerated columns
\newcolumntype{e}[1]{%
    >{\minipage[t]{\linewidth}\let\\\tabularnewline
      \enumerate
      \addtolength{\rightskip}{0pt plus 50pt}% for raggedright
      \setlength{\itemsep}{-\parsep}}%
    p{#1}%
    <{\@finalstrut\@arstrutbox\endenumerate\endminipage}}

%---- Itemized columns
\newcolumntype{i}[1]{%
    >{\minipage[t]{\linewidth}\let\\\tabularnewline
      \itemize
      \addtolength{\rightskip}{0pt plus 50pt}% for raggedright
      \setlength{\itemsep}{-\parsep}}%
    p{#1}%
    <{\@finalstrut\@arstrutbox\enditemize\endminipage}}
\makeatother

\begin{document}
\begin{longtable}{| p{3cm} |p{6cm}|}
    \hline%
    text &
    \begin{itemize}[topsep=0ex,partopsep=0ex]
    \item Produkt und Quotient
    \item Produkt und Quotient
    \end{itemize}
    \\ \hline
    text &
    \multicolumn{1}{i{6cm}|}{
    \item Produkt und Quotient
    \item Produkt und Quotient
    }\\ \hline
\end{longtable}

\begin{center}
\begin{tabular}{| p{3cm} |p{6cm}|}
    \hline%
    text &
    \begin{itemize}[topsep=0ex,partopsep=0ex]
    \item Produkt und Quotient
    \item Produkt und Quotient
    \end{itemize}
    \\ \hline
    text &
    \multicolumn{1}{i{6cm}|}{
    \item Produkt und Quotient
    \item Produkt und Quotient
    }\\ \hline
\end{tabular}
\end{center}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.