TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 22 down vote accepted

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.

share|improve this answer
Thanks, exactly what I needed! – Yiannis Lazarides Oct 12 '10 at 16:19

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

share|improve this answer
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  \\

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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