为什么 longtable 不能处理行内的 \medskip,而 tabular 可以?

为什么 longtable 不能处理行内的 \medskip,而 tabular 可以?

如何才能做到longtable不忽略\midskip表格行的开头?

在下面的 MWE 中,我尝试在一行中添加一些空格。 它适用于tabular,但不适用于longtable

以下是tabularMWE:

\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}

编译后结果为lualatex

Mathematica 图形

现在我做同样的事情,但使用longtable。没有其他变化。内表上方的空间现在消失了(但其下方的空间仍然存在):

\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}

Mathematica 图形

我有点记得看到过类似的东西。有些东西longtable处理空格的方式略有不同,但我记不清是什么了。

如何使 makelongtable生成与 相同的输出tabular?我的表很长,这就是为什么我需要使用longtable

屏幕日志

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
 read cache: /usr/local/texlive/2017/texmf-var/luatex-cache/generic /home/me/.t
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
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/size10.clo(load luc: /home/m
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.

答案1

longtable 在 p-cell 的开头插入一个支柱。这意味着 TeX 不再处于垂直模式,因此会\medskip产生不同的效果。如果删除此支柱,输出将相同(但可能会产生副作用...):

编辑

该问题已报告(https://www.latex-project.org/cgi-bin/ltxbugs2html.new?pr=tools/3785)。所以解决方案是已知的,主要的问题是如何在不破坏现有文档的情况下添加到 longtable 中……

\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} 

在此处输入图片描述

答案2

正如 Ulrike 指出的那样,这种差异是由于支柱处理方式的差异造成的。

您正在使用array

一般来说longtable遵循array用法,它记录

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

然而,最近发生了变化,但array并未反映在longtable

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

但是longtable使用 1992 年之前的版本

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

array您可能会认为和软件包的作者longtable在过去 25 年内可能相互进行过交流,但显然并没有。

答案3

您可以使用\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$ &
\vadjust pre{\vspace{\medskipamount}}%
\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}

还请注意正确的输入(不要使用\left\right\dotsc而要使用\cdots)。和 的[c]选项不同(但两者都是默认选项)。longtabletabular

在此处输入图片描述

答案4

以下解决方案在环境中有效,虽然有些黑客攻击,但可以longtable:在环境中插入\vskip*{-\medskipamount} 在框架表格之前立即添加一个空白行,然后插入一个空白行带框的表格。

在此处输入图片描述

\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
\endfirsthead
\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}

相关内容