我是一个团队的一员,该团队正在协作准备一个包含使用 LaTeX 的表格和多媒体内容的大型文档(使用 lualatex 发布为 PDF),我们遇到了一个持续存在的问题,即文档中有一页的文本内容溢出了页面末尾,如下所示:
我们相信我们已经找到了原因,以下是用于产生上述内容的 MWE:
\documentclass[a4paper]{report}
\usepackage[margin=2.54cm]{geometry}
\usepackage{lipsum}
%\usepackage{showframe}
\usepackage{longtable}
\usepackage[draft]{graphicx}
%\graphicspath{ {Resources/} }
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\section{Section here}
\subsection{Subsection here}
\lipsum[1-2]
\begin{figure}
\caption{Caption 1}
\includegraphics[height=9.24cm]{image1.png}
\end{figure}
\subsection{Subsection here}
\lipsum[1]
\begin{figure}
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed consequat ex vitae}
\includegraphics[height=9.60cm]{image2.png}
\end{figure}
\lipsum[1-3]
\begin{longtable}{|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\cline{1-6}
& Text & Text & Text & Text & Text\\
\cline{1-6}
\end{longtable}
\lipsum[1-6]
\end{document}
我们遇到的问题似乎是记录在https://www.latex-project.org/cgi-bin/ltxbugs2html?pr=tools/3512,这是由于 longtable 包在跟随浮点数时错误地重置了 pagegoal 所致。
针对此问题有一个建议的修复方案,之前已在分页符不适用于浮动和 longtabu,但在这两种情况下,修复都早于 Longtable 的当前版本,并且我们理想情况下希望避免尝试在整个团队中维护 Longtable 的修补版本。
是否有人知道我们可以用文档本地修复方法来解决这个问题?
答案1
抱歉,我试图将错误报告的周转时间控制在 20 年以内,但这并不总是那么容易......
您可以根据文档中引用的报告中建议的更改,而不必修改文件.sty
。
\documentclass[a4paper]{report}
\usepackage[margin=2.54cm]{geometry}
\usepackage{lipsum}
%\usepackage{showframe}
\usepackage{longtable}
\makeatletter
\def\LT@start{%
\let\LT@start\endgraf
\endgraf\penalty\z@\vskip\LTpre\endgraf
\dimen@\pagetotal
\advance\dimen@ \ht\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
\advance\dimen@ \dp\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
\advance\dimen@ \ht\LT@foot
\dimen@ii\vfuzz
\vfuzz\maxdimen
\setbox\tw@\copy\z@
\setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
\setbox\tw@\vbox{\unvbox\tw@}%
\vfuzz\dimen@ii
\advance\dimen@ \ht
\ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@\dp
\ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
\advance\dimen@ -\pagegoal
\ifdim \dimen@>\z@\vfil\break\fi
\global\@colroom\@colht
\ifvoid\LT@foot\else
% \advance\vsize-\ht\LT@foot
\global\advance\vsize-\ht\LT@foot
\global\advance\@colroom-\ht\LT@foot
\dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
\maxdepth\z@
\fi
\ifvoid\LT@firsthead\copy\LT@head\else\box\LT@firsthead\fi\nobreak
\output{\LT@output}}
\def\endlongtable{%
\crcr
\noalign{%
\let\LT@entry\LT@entry@chop
\xdef\LT@save@row{\LT@save@row}}%
\LT@echunk
\LT@start
\unvbox\z@
\LT@get@widths
\if@filesw
{\let\LT@entry\LT@entry@write\immediate\write\@auxout{%
\gdef\expandafter\noexpand
\csname LT@\romannumeral\c@LT@tables\endcsname
{\LT@save@row}}}%
\fi
\ifx\LT@save@row\LT@@save@row
\else
\LT@warn{Column \@width s have changed\MessageBreak
in table \thetable}%
\LT@final@warn
\fi
\endgraf\penalty -\LT@end@pen
%
\ifvoid\LT@foot\else
\global\advance\vsize\ht\LT@foot
\global\advance\@colroom\ht\LT@foot
\dimen@\pagegoal\advance\dimen@\ht\LT@foot\pagegoal\dimen@
\fi
%
\endgroup
\global\@mparbottom\z@
% \pagegoal\vsize
\endgraf\penalty\z@\addvspace\LTpost
\ifvoid\footins\else\insert\footins{}\fi}
\def\LT@output{%
\ifnum\outputpenalty <-\@Mi
\ifnum\outputpenalty > -\LT@end@pen
\LT@err{floats and marginpars not allowed in a longtable}\@ehc
\else
\setbox\z@\vbox{\unvbox\@cclv}%
\ifdim \ht\LT@lastfoot>\ht\LT@foot
\dimen@\pagegoal
%
\advance\dimen@\ht\LT@foot
%
\advance\dimen@-\ht\LT@lastfoot
\ifdim\dimen@<\ht\z@
\setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}%
\@makecol
\@outputpage
%
\global\vsize\@colroom
%
\setbox\z@\vbox{\box\LT@head}%
\fi
\fi
% \global\@colroom\@colht
% \global\vsize\@colht
% \vbox
% {\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}%
\unvbox\z@\ifvoid\LT@lastfoot\copy\LT@foot\else\box\LT@lastfoot\fi
\fi
\else
\setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
\@makecol
\@outputpage
\global\vsize\@colroom
\copy\LT@head\nobreak
\fi}
\makeatother
\usepackage[draft]{graphicx}
%\graphicspath{ {Resources/} }
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
\section{Section here}
\subsection{Subsection here}
\lipsum[1-2]
\begin{figure}
\caption{Caption 1}
\includegraphics[height=9.24cm]{image1.png}
\end{figure}
\subsection{Subsection here}
\lipsum[1]
\begin{figure}
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed consequat ex vitae}
\includegraphics[height=9.60cm]{image2.png}
\end{figure}
\lipsum[1-3]
\begin{longtable}{|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\cline{1-6}
& Text & Text & Text & Text & Text\\
\cline{1-6}
\end{longtable}
\lipsum[1-6]
\end{document}