# Why does longtable not process \medskip inside a row, but tabular does?

How can one make longtable not ignore \midskip at start of a table row?

In the following MWE, I am trying to add little space in a row. It works OK with tabular, but not in longtable.

Here is a tabular MWE:

\documentclass[]{article}
\usepackage{amsmath}
\usepackage{array}
\renewcommand{\arraystretch}{1.25}

\begin{document}

\begin{tabular}
[c]{|l|l|m{3in}|}\hline
Left & right & eigenvalues and corresponding eigenfunction\\\hline
$y\left( 0\right) =0$ & $y\left( L\right) =0$ &
\medskip
\begin{tabular}
[c]{|l|l||l|}\hline
$\lambda<0$ & None & None\\\hline
$\lambda=0$ & None & None\\\hline
$\lambda>0$ & $\left( \frac{n\pi}{L}\right) ^{2}\qquad n=1,2,3,\cdots$ &
$\sin\left( \frac{n\pi}{L}x\right)$\\\hline
\end{tabular}
\medskip
\\\hline
\end{tabular}

\end{document}


Which gives after compiling with lualatex:

Now I do the same exact thing, but use longtable. No other changes. The space above the inner table now is gone (but the one below it remains there):

\documentclass[]{article}
\usepackage{amsmath}
\usepackage{array}
\renewcommand{\arraystretch}{1.25}
\usepackage{longtable}

\begin{document}

\begin{longtable}
[c]{|l|l|m{3in}|}\hline
Left & right & eigenvalues and corresponding eigenfunction\\\hline
$y\left( 0\right) =0$ & $y\left( L\right) =0$ &
\medskip
\begin{tabular}
[c]{|l|l||l|}\hline
$\lambda<0$ & None & None\\\hline
$\lambda=0$ & None & None\\\hline
$\lambda>0$ & $\left( \frac{n\pi}{L}\right) ^{2}\qquad n=1,2,3,\cdots$ &
$\sin\left( \frac{n\pi}{L}x\right)$\\\hline
\end{tabular}
\medskip
\\\hline
\end{longtable}

\end{document}


I sort of remember seeing something like this. Something about longtable handles spaces little differently, but I can't recall what it is.

How can make longtable generate the same output as tabular? My table is long, and that is why I need to use longtable.

### Screen log

lualatex foo.tex
This is LuaTeX, Version 1.0.4 (TeX Live 2017)
restricted system commands enabled.
(./foo.tex
LaTeX2e <2017-04-15>
(using write cache: /home/me/.texlive2017/texmf-var/luatex-cache/generic)(using
exlive2017/texmf-var/luatex-cache/generic)
luaotfload | main : initialization completed in 0.129 seconds
Babel <3.15> and hyphenation patterns for 1 language(s) loaded.
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
e/.texlive2017/texmf-var/luatex-cache/generic/fonts/otl/lmroman10-regular.luc))
) (/usr/local/texlive/2017/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the ?' option.
(/usr/local/texlive/2017/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2017/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2017/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2017/texmf-dist/tex/latex/tools/array.sty)
(/usr/local/texlive/2017/texmf-dist/tex/latex/tools/longtable.sty) (./foo.aux)
Underfull \vbox (badness 10000) detected at line 23
[1{/usr/local/texlive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./foo.aux))
(see the transcript file for additional information)
450 words of node memory still in use:
5 hlist, 2 vlist, 2 rule, 2 glue, 1 kern, 5 attribute, 53 glue_spec, 5 attri
bute_list, 1 write nodes
avail lists: 2:159,3:30,4:2,5:37,6:242,7:363,8:89,9:168,11:14
</usr/local/texlive/2017/texmf-dist/fonts/opentype/public/lm/lmroman10-regular.
otf></usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm/cmex10.p
fb></usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pf
b></usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi7.pfb>
</usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></
usr/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm/cmr7.pfb></usr
/local/texlive/2017/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy10.pfb>
Output written on foo.pdf (1 page, 53623 bytes).
Transcript written on foo.log.

• Not an answer to the "why" question, but change your [c] parameter to [t] in the longtable version and it will do what you want. – Alan Munn Feb 3 '18 at 0:51
• @AlanMunn - This solution does leave some space above the framed tabular in the third column. However, the framed tabular is not guaranteed to be aligned with the material in the first two rows. – Mico Feb 3 '18 at 0:53
• @Mico Ah, right. I didn't think about that issue. – Alan Munn Feb 3 '18 at 0:54
• this is actually rather a good question, I don't see the answer immediately, but I'm travelling today so may not get back to it, a challenge for egreg to investigate before I get home:-) – David Carlisle Feb 3 '18 at 9:15

longtable inserts a strut at the begin of p-cell. This means that TeX is no longer in vertical mode and so the \medskip has a different effect. If one remove this strut the output is identical (but it could have side effects ...):

## Edit

The Issue has been reported (https://www.latex-project.org/cgi-bin/ltxbugs2html.new?pr=tools/3785). So the solution is known, the main question is how to add to longtable without breaking existing documents ...

\documentclass[]{article}
\usepackage{longtable}
\begin{document}
\LTleft=\parindent

\begin{tabular}{p{3in}}\hline
\relax\ifvmode yes \else no \fi %\medskip
xxxx
\medskip
\\\hline
\end{tabular}

\begin{longtable}{p{3in}}\hline
\relax\ifvmode yes \else no \fi %\medskip
xxxx
\medskip
\\\hline
\end{longtable}

\begin{tabular}{p{3in}}\hline
\medskip
xxxx
\medskip
\\\hline
\end{tabular}

\makeatletter
\def\LT@startpbox#1{%
\bgroup
\let\@footnotetext\LT@p@ftntext
\setlength\hsize{#1}%
\@arrayparboxrestore
%\vrule \@height \ht\@arstrutbox \@width 1pt
}
\makeatother
\begin{longtable}{p{3in}}\hline
\medskip
xxxx
\medskip
\\\hline
\end{longtable}
\end{document}


As Ulrike pointed out, the difference is due to a difference in strut handling.

You are using array package

In general longtable follows array usage, it documents

% The rest of this macro is mainly based on \package{array} package, but
% should work for the standard \env{tabular} too.


However there was a more recent change to array that is not reflected in longtable

% \changes{v2.1c}{1992/12/14}{Use everypar to insert strut}
%    \begin{macrocode}
\everypar{%
\vrule \@height \ht\@arstrutbox \@width \z@
\everypar{}}%
}
%    \end{macrocode}


However longtable uses the pre 1992 version

    \vrule \@height \ht\@arstrutbox \@width \z@}


You would think the authors of the array and longtable packages might have communicated with each other during the last 25 years but apparently not.

You can use \vadjust pre

\documentclass[]{article}
\usepackage{amsmath}
\usepackage{array}
\renewcommand{\arraystretch}{1.25}
\usepackage{longtable}

\begin{document}

\begin{center}
\begin{tabular}{|l|l|m{3in}|}\hline
Left & right & eigenvalues and corresponding eigenfunction\\\hline
$y(0) = 0$ & $y(L) = 0$ &
\medskip
\begin{tabular}{|l|l||l|}\hline
$\lambda<0$ & None & None\\\hline
$\lambda=0$ & None & None\\\hline
$\lambda>0$ & $(\frac{n\pi}{L})^{2}\qquad n=1,2,3,\dotsc$ &
$\sin(\frac{n\pi}{L}x)$\\\hline
\end{tabular}\medskip
\\\hline
\end{tabular}
\end{center}

\begin{longtable}{|l|l|m{3in}|}\hline
Left & right & eigenvalues and corresponding eigenfunction\\\hline
$y(0) = 0$ & $y(L) = 0$ &
\begin{tabular}{|l|l||l|}\hline
$\lambda<0$ & None & None\\\hline
$\lambda=0$ & None & None\\\hline
$\lambda>0$ & $(\frac{n\pi}{L})^{2}\qquad n=1,2,3,\dotsc$ &
$\sin(\frac{n\pi}{L}x)$\\\hline
\end{tabular}\vspace{\medskipamount}
\\\hline
\end{longtable}

\end{document}


Please, note also the proper input (no \left and \right; \dotsc instead of \cdots). The [c] option is different for longtable and tabular (but is the default for both).

I don't know why, but it's as simple to use the \Gape command, from makecell. For the nested tabular, it looks nicer to use hhline.

\documentclass[]{article}
\usepackage{amsmath, nccmath}
\usepackage{array}
\usepackage{longtable, makecell}
\usepackage{hhline}

\begin{document}

\setlength{\extrarowheight}{2pt}
\begin{longtable}
[c]{|l|l|m{3in}|}
\hline
Left & right & eigenvalues and corresponding eigenfunction\\\hline
$y\left( 0\right) =0$ & $y\left( L\right) =0$ &
\medskip
\Gape[6pt][0pt]{\setcellgapes{2pt}\makegapedcells\begin{tabular}
[c]{|l|l||l|}\hline
$\lambda<0$ & None & None\\ \hhline{|-|-||-|}
$\lambda=0$ & None & None\\ \hhline{|-|-||-|}
$\lambda>0$ & $\Bigl( \mfrac{n\pi}{L}\Bigr)^{\!2}\qquad n=1,2,3,\cdots$ &
$\sin\Bigl( \mfrac{n\pi}{L}x\Bigr)$\\\hline
\end{tabular}}
\\\hline
\end{longtable}

\end{document}


The following, admittedly somewhat hackish, solution works in a longtable env: Insert both a \vskip*{-\medskipamount} and a blank line immediately before the framed tabular, and insert a blank line after the framed tabular.

\documentclass{article}
\usepackage{amsmath,array,longtable}
\setlength\extrarowheight{2pt}

\begin{document}

% first, a centered "tabular" env.
\begin{center}
\begin{tabular}[c]{|l|l|m{3in}@{}|}\hline
Left & right & eigenvalues and corresponding eigenfunctions\\\hline
$y(0) =0$ & $y(L) =0$ &
\medskip
\begin{tabular}{|l|l||l|}
\hline
$\lambda<0$ & None & None\\ \hline
$\lambda=0$ & None & None\\ \hline
$\lambda>0$ & $\bigl( \frac{n\pi}{L}\bigr)^{2\mathstrut} \qquad n=1,2,3,\dots$ &
$\sin\bigl( \frac{n\pi}{L\mathstrut}x \bigr)$\\
\hline
\end{tabular}
\medskip
\\ \hline
\end{tabular}
\end{center}

% second, a longtable env.
\begin{longtable}{|l|l|m{3in}@{}|}
\hline
Left & right & eigenvalues and corresponding eigenfunctions\\ \hline
\hline
\endlastfoot

$y(0) =0$ & $y(L) =0$ &
\vspace*{-\medskipamount}
% leave a blank line

\begin{tabular}{|l|l||l|}
\hline
$\lambda<0$ & None & None\\ \hline
$\lambda=0$ & None & None\\ \hline
$\lambda>0$ & $\bigl( \frac{n\pi}{L}\bigr)^{2\mathstrut} \qquad n=1,2,3,\dots$ &
$\sin\bigl( \frac{n\pi}{L\mathstrut}x \bigr)$\\
\hline
\end{tabular}
% leave a blank line

\\ \hline
\end{longtable}
\end{document}
`