7

I want to measure the remaining space and use that number on another page. I tried the following:

\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}
student
  • 29,003
  • try \edef\measurepage{\the\dimexpr\pagegoal-\pagetotal-\baselineskip\relax} and use it \measurepage – touhami May 10 '16 at 18:02
  • 1
    note that any such calculation is only approximate: tex's page breaker acts at a different time long after that value is calculated – David Carlisle May 10 '16 at 21:32
  • @DavidCarlisle There ie no way to converge to the appropriate value after 1 or 2 compilations? I tried to add \edef\measurepage{\the\dimexpr\pagegoal-\pagetotal\relax}\rule{1mm}{\measurepage} and it is always moved to the next page if I don't also substract a small number like 3pt. – tobiasBora Sep 30 '21 at 17:41

3 Answers3

8

For more details

What is the difference between \def and \newcommand?

What is the difference between \let and \edef?

A solution is to use \edef method

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

MWE

\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}

enter image description here

touhami
  • 19,520
6

This might work too. I use the existing definition of \measurepage, but set a new length, \remainder, to its value. I then use \remainder in the minipage argument.

\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}

enter image description here

5

You can get more exact values by storing the actuall positions in the aux-file. This need two compilations (the x are only there to show the locations):

\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}

enter image description here

Ulrike Fischer
  • 327,261