页面顶部定位:\longtable 与 \tabular

页面顶部定位:\longtable 与 \tabular

为什么longtable页面顶部的环境与垂直放置的tabular环境不同?我在这个问题上花了好几天的时间,却没有找到longtable以同样的方式垂直对齐的方法。

代码:

\documentclass[11pt,a4paper]{article}
\usepackage{longtable}

\newcommand{\lorem}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pellentesque iaculis nunc eget congue. Etiam lobortis nisi velit. Proin tristique massa a lectus ullamcorper semper. Aenean ut dignissim diam. Integer ullamcorper eros nibh. Cras molestie neque quis lectus lobortis egestas. Maecenas vel tortor in nulla sagittis venenatis. Nulla ac eros dui, eget lacinia ante. Fusce elementum nisl ac tortor hendrerit id lacinia orci malesuada. Praesent eu iaculis mi. Vestibulum sodales tempor rutrum. }
\newcommand{\examplelongtable}{%
    \begin{longtable}{|l|p{58mm}|}
    %
    \hline
    \endfirsthead
    %
    \hline\multicolumn{2}{|l|}{\textsl{\ldots continued}}
    \endhead
    %
    \multicolumn{2}{|l|}{\textsl{will be continued\ldots}}\\*
    \hline
    \endfoot
    %
    \hline
    \endlastfoot
    %
    aa: & 4711\\
    \hline%
    aaa: & 2\\
    \hline%
    aaaa: & 4711-2\\
    \end{longtable}
}
\newcommand{\exampletabular}{%
    \begin{tabular}[H]{|l|p{58mm}|}
    \hline
    aa: & 4711\\
    \hline%
    aaa: & 2\\
    \hline%
    aaaa: & 4711-2\\
    \hline
    \end{tabular}
}
\setlength{\parskip}{1.0\baselineskip}
\setlength{\LTpre}{0pt}
\setlength{\LTpost}{0pt}
\setlength{\LTleft}{\parindent}

\begin{document}
\exampletabular

\lorem

\lorem

\lorem

\lorem

\lorem
\examplelongtable
\end{document}

据说有一个非常简单的解决方案,但我似乎无法找到它......

\newpage如果我在示例之前明确设置一个longtable,那么经过调整的\vspace*{-...}将会有所帮助,但在常规的分页符上则不会,因为源代码并不“知道”它出现在哪里。

答案1

不深入研究,我通过实验发现以下内容仅适用于0pt \topskip和 外边框表格:根据表格类型之前的内容,在表格之前应用不同的度量。只有当tabular之后tabular,才不需要添加任何内容。因此,所有距离都好像只会tabular被使用(注意:没有table环境,所以不是浮动的,只是在原地)。

代码使用不同的\parskip和值进行测试\arrayrulewidth(编辑:和\lineskip)。准确度约为 0.05pt。两个表格变体可以互换,分页符有效(所有内容都与页面上边框垂直对齐)。

\documentclass[11pt,a4paper]{article}
\usepackage{longtable}

\newcommand{\lorem}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pellentesque iaculis nunc eget congue. Etiam lobortis nisi velit. Proin tristique massa a lectus ullamcorper semper. Aenean ut dignissim diam. Integer ullamcorper eros nibh. Cras molestie neque quis lectus lobortis egestas. Maecenas vel tortor in nulla sagittis venenatis. Nulla ac eros dui, eget lacinia ante. Fusce elementum nisl ac tortor hendrerit id lacinia orci malesuada. Praesent eu iaculis mi. Vestibulum sodales tempor rutrum. }
\newcommand{\examplelongtable}{%
    \begin{longtable}[H]{|l|p{58mm}|}
    %
    \hline
    \endfirsthead
    %
    \hline\multicolumn{2}{|l|}{\textsl{\ldots continued}}
    \endhead
    %
    \multicolumn{2}{|l|}{\textsl{will be continued\ldots}}\\*
    \hline
    \endfoot
    %
    \hline
    \endlastfoot
    %
    aa: & 4711\\
    \hline%
    aaa: & 2\\
    \hline%
    aaaa: & 4711-2\\
    \end{longtable}
}
\newcommand{\exampletabular}{%
    \begin{tabular}[t]{|l|p{58mm}|}
    \hline%
    aa: & 4711\\
    \hline%
    aaa: & 2\\
    \hline%
    aaaa: & 4711-2\\
    \hline
    \end{tabular}
}
\setlength{\parskip}{1.0\baselineskip}

\begin{document}
\setlength{\topskip}{0pt}
\setlength{\LTpre}{0pt}
\setlength{\LTpost}{\dimexpr\lineskip-6.0pt\relax}  % If '\lineskip' (or the whichever 6.0pt measure) would be changed after this line, '\LTpost' would become out of date.
\setlength{\LTleft}{\parindent}

\lorem

\newpage

%\lorem

\vspace{-\parskip}
\exampletabular

\vspace{\dimexpr\parskip+\lineskip\relax}%  % Only if 'tabular' is followed by a 'longtable'.
\examplelongtable

\vspace{\dimexpr\parskip+6.0pt\relax}%  % Only if 'longtable' is followed by another 'longtable'.
\examplelongtable

\vspace{\dimexpr\arrayrulewidth-7.57pt\relax}%  % Only if 'longtable' is followed by a 'tabular'.
\exampletabular

\exampletabular

\vspace{\dimexpr\parskip+\lineskip\relax}%  % Only if 'tabular' is followed by a 'longtable'.
\examplelongtable

\lorem

\lorem

\lorem

\vspace{\dimexpr\baselineskip-\arrayrulewidth-2.08pt\relax}%    % Only if text is followed by a 'longtable'.
\examplelongtable

\lorem
\end{document}

注意这个问题关于longtable分页符可能也很有趣。

有人知道该措施的起源和名称6.0pt,或其他两种扭曲措施吗?

相关内容