Is there a way to compute the remaining space on the current page and issue an optional command?


See the needspace package. It might do what you need, or at least give inspiration for whatever it is you're trying to do :-) Namely, the \pagegoal and \pagetotal registers should help.


In ConTeXt, \testpage[n] checks if there is enough space for n lines.

  • Thanks! I think it is high time I start migrating to ConTeXt it seems to be the answer to a lot of difficult issues. – Yiannis Lazarides Oct 13 '10 at 12:56

Here is a small example demonstrating how the accepted answer's \pagetotal etc behave -- note they only seem to change after a \par (click for high resolution image):


Here is the code used for it:


% http://www.tug.org/utilities/plain/cseq.html#pagedepth-rp

\tpageitemsB: ligula aliquet magna,  \\
\tpageitemsB:  Morbi ac orci et nisl \\
\tpageitemsB: Suspendisse ut massa.  \\
\tpageitemsB: a nulla. Cum sociis na \\
\tpageitemsB: dis parturient montes, \\
\tpageitemsB: Aliquam tincidunt urna \\
\tpageitemsB: vestibulum turpis. Pel \\
\tpageitemsB: mauris.                \\

\tpageitemsB: Nulla malesuada porttitor  \par\noindent
\tpageitemsB: congue non, volutpat       \par\noindent
\tpageitemsB: libero. Vi- vamus viverra  \par\noindent
\tpageitemsB: nonummy pel- lentesque     \par\noindent
\tpageitemsB: semper elit. Proin fer     \par\noindent
\tpageitemsB: diam turpis, molestie vita \par\noindent
\tpageitemsB: nec, leo. Maecenas lacinia \\
\tpageitemsB: eleifend at, accumsan nec, \\
\tpageitemsB: Morbi blandit ligula feugi \\
\tpageitemsB: consequat lorem. Sed lacin \\
\tpageitemsB: Pellentesque tincidunt pur \\
\tpageitemsB: non enim. Praesent euis    \\
\tpageitemsB: mobibendum quam in telus.  \\
\tpageitemsB: lectus. Donec et mi. Nam v \\
\tpageitemsB: Vestibu- lum pellentesque  \\
\tpageitemsB: Quisque ullamcorper placer \\
\tpageitemsB: Morbi vel justo vitae lacu \\
\tpageitemsB: Lorem ipsum do- lor sit am \\
\tpageitemsB: adipiscing elit. In hac ha \\
\tpageitemsB: Integer tempus convallis a \\
\tpageitemsB: Nunc elementum fermentum w \\
\tpageitemsB: imperdiet, enim sed gravid \\
\tpageitemsB: odio placerat quam, ac pul \\
\tpageitemsB: enim. Nunc vitae tortor. P \\
\tpageitemsB: amet nisl. Vi- vamus quis  \\
\tpageitemsB: vehicula.                  \\

\tpageitemsB: Fusce mauris. Vestibulum l \\
\tpageitemsB: Sed bibendum, nulla a fauc \\
\tpageitemsB: ultricies tellus, ac venen \\
\tpageitemsB: Vestibulum diam. Aliquam p \\
\tpageitemsB: sagittis posuere, turpis l \\
\tpageitemsB: hendrerit risus eros eget  \\
\tpageitemsB: erat in sapien mattis port \\
\tpageitemsB: porttitor. Nulla facilisi. \\
\tpageitemsB: com- modo facilisis. Morbi \\
\tpageitemsB: dignissim inter- dum, just \\
\tpageitemsB: et vehicula libero dui cur \\
\tpageitemsB: ligula sed lacus. Duis cur \\
\tpageitemsB: ac magna. Cras nulla. Null \\
\tpageitemsB: leo. Quisque egestas wisi  \\


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.