longtable 中的 \nopagebreak 会导致不需要的负垂直空间

longtable 中的 \nopagebreak 会导致不需要的负垂直空间

系统:XeTeX 版本 3.14159265-2.6-0.99992(TeX Live 2015/W32TeX)。

MWE(叠加网格以帮助形象化问题):

\documentclass[12pt]{book}
\usepackage[top=72pt,left=72pt,bottom=72pt,right=72pt,width=396pt,height=612pt]{geometry}
\usepackage[step=18pt]{pagegrid}
\pagegridsetup{top-left}
\usepackage{longtable,ltabptch}
\usepackage{lipsum}
\setlength{\LTpre}{0pt}
\setlength{\LTpost}{0pt}
\begin{document}
\fontsize{12}{18}\selectfont
\vspace*{6.5pt}
% No space deleted with \nopagebreak on next line
\lipsum[2] \nopagebreak
\lipsum[2]
\begin{longtable}{ll} C11 & C12\\ C21 & C22 \end{longtable}
\lipsum[2]
% Use of \nopagebreak in the longtable deletes some vertical space and line spacing is disturbed
\begin{longtable}{ll} C11 & C12\\ \nopagebreak C21 & C22 \\ \nopagebreak \end{longtable}
\lipsum[2]
\end{document}

输出:

在此处输入图片描述

答案1

这个答案是一个肮脏的黑客,但有效。通过反复试验,我发现只有\nopagebreak在 longtable 的第一行中使用时才会出现问题。所以我创建了一个没有的空白第一行\nopagebreak,然后添加了等于的负垂直空间\baselineskip。代码是:

\documentclass[12pt]{book}
\usepackage[top=72pt,left=72pt,bottom=72pt,right=72pt]{geometry}
\usepackage[step=18pt]{pagegrid}
\pagegridsetup{top-left}
\usepackage{longtable,ltabptch}
\usepackage{lipsum}
\setlength{\LTpre}{0pt}
\setlength{\LTpost}{0pt}
\begin{document}
\fontsize{12}{18}\selectfont
\vspace*{6.5pt}
% No space deleted with \nopagebreak on next line
\lipsum[2] \nopagebreak
\lipsum[2]
\begin{longtable}{ll}
C11 & C12\\
C21 & C22
\end{longtable}
\lipsum[2]
\newlength{\mylen}
\setlength{\mylen}{\baselineskip}
\begin{longtable}{ll}
% Add a dummy first line and then add negative vertical space equal to \baselineskip
 & \\ [-\the\mylen]
C11 & C12\\ \nopagebreak
C21 & C22 \\ \nopagebreak
\end{longtable}
\lipsum[2]
\end{document}

输出结果如下:

长桌固定

相关内容