测量页面上的剩余空间并将其用于另一页

测量页面上的剩余空间并将其用于另一页

我想测量剩余空间并在另一页上使用该数字。我尝试了以下操作:

\documentclass[a4paper,12pt]{article}

\usepackage[top=2cm,bottom=2cm,hmargin=2cm]{geometry}

\usepackage{lipsum}

\begin{document}

\section*{Firstpage}

\lipsum[1-4]

\newcommand\measurepage{\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}

%%The value seems to be calculated correctly
\the\measurepage

\newpage

\section*{Secondpage}
%% Skip the measured space from the page before

\vfill

%%This is not the value stored above
\the\measurepage

\begin{minipage}[t][\measurepage][t]{\textwidth}
\lipsum[3]
\end{minipage}


\end{document}

答案1

更多细节

\def 和 \newcommand 之间有什么区别?

\let 和 \edef 之间有什么区别?

解决方案是使用\edef方法

\edef\measurepage{\the\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}

平均能量损失

\documentclass[a4paper,12pt]{article}

\usepackage[top=2cm,bottom=2cm,hmargin=2cm]{geometry}

\usepackage{lipsum}

\begin{document}

\section*{Firstpage}

\lipsum[1-4]

\edef\measurepage{\the\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}

%%The value seems to be calculated correctly
\measurepage

\newpage

\section*{Secondpage}
%% Skip the measured space from the page before

\vfill

%%This is not the value stored above
\measurepage

\begin{minipage}[t][\measurepage][t]{\textwidth}
\lipsum[3]
\end{minipage}

\end{document}

在此处输入图片描述

答案2

这可能也有效。我使用现有的定义\measurepage,但将新长度设置为其值。然后在参数中\remainder使用。\remainderminipage

\documentclass[a4paper,12pt]{article}
\usepackage[top=2cm,bottom=2cm,hmargin=2cm]{geometry}

\usepackage{lipsum}
\newlength\remainder
\newcommand\measurepage{\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}
\begin{document}

\section*{Firstpage}

\lipsum[1-4]


%%The value seems to be calculated correctly
\remainder=\measurepage\relax\the\remainder

\newpage

\section*{Secondpage}
%% Skip the measured space from the page before

\vfill

%%This is not the value stored above
\the\measurepage

\begin{minipage}[t][\remainder][t]{\textwidth}
\lipsum[3]
\end{minipage}


\end{document}

在此处输入图片描述

答案3

您可以通过将实际位置存储在辅助文件中来获得更精确的值。这需要两次编译(x 仅用于显示位置):

\documentclass[a4paper,12pt]{article}

\usepackage[top=2cm,bottom=2cm,hmargin=2cm]{geometry}

\usepackage{lipsum}
\usepackage{zref-savepos}

\begin{document}

\section*{Firstpage}

\lipsum[1-4]

x\zsavepos{start}\par\vfill\mbox{x}\zsavepos{end}

\newpage

\section*{Secondpage}
%% Skip the measured space from the page before

\vfill

%the y position has its zero at the bottom
\begin{minipage}[t][\dimexpr\zposy{start}sp-\zposy{end}sp][t]{\textwidth}
\lipsum[3]\vfill xxxx
\end{minipage}


\end{document}

在此处输入图片描述

相关内容