![测量页面上的剩余空间并将其用于另一页](https://linux22.com/image/333782/%E6%B5%8B%E9%87%8F%E9%A1%B5%E9%9D%A2%E4%B8%8A%E7%9A%84%E5%89%A9%E4%BD%99%E7%A9%BA%E9%97%B4%E5%B9%B6%E5%B0%86%E5%85%B6%E7%94%A8%E4%BA%8E%E5%8F%A6%E4%B8%80%E9%A1%B5.png)
我想测量剩余空间并在另一页上使用该数字。我尝试了以下操作:
\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
更多细节
解决方案是使用\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
使用。\remainder
minipage
\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}