following scenario: I want to automatically generate a newsletter with some small articles, which is working fine. (I am generating LaTeX-code with data from a small database). But now I want to include some images to fill the space left (I want to have entirely filled pages), but I don't want to get more pages than needed for the articles.

So: is there a way to check with LaTeX, if there is space left on the last page and how much?

I hope you can understand what I mean.

2 Answers 2


I think you could use \pagetotal for this. Subtract it from \textheight to get the amount of space remaining.


\advance\spaceleft by -\pagetotal
\typeout{Space on last page:}

The result of this is:

Space on last page:


  • 2
    Instead of multiplying something by -1 twice you can simply write \advance\spaceleft by-\pagetotal.
    – wipet
    Commented Jun 5, 2017 at 8:40
  • Any idea why if I replace the last two lines with \rule{1mm}{\spaceleft}, the rule is pushed on the next page? There should be enough space for it right?
    – tobiasBora
    Commented Sep 30, 2021 at 15:49
  • @tobiasBora --- One problem was a missing paragraph break before \advance. That meant the last paragraph wasn't included in page total. With that fixed, you still need to remove 3 or 4pt from the rule height to prevent a page break. I'm not sure why this happens exactly. I'll give it some thought, but you will probably get an answer much more quickly if you post a new question about it (because then someone like egreg or David Carlisle will see it). Commented Oct 1, 2021 at 14:43

A nicer way to realise Ian Thompsons answer is to simply use \dimexpr rather than multiplying by -1 and adding the lengths:




Remaining space (above this line):
  • 2
    Well, this code snippet doesn't suffice (Ian Thompson's does). Please add the missing parts.
    – TeXnician
    Commented Jun 5, 2017 at 7:36
  • \dimexpr belongs to e-TeX extensions. That's why hoop jumping might be necessary for some plain TeX users.
    – percusse
    Commented Jun 5, 2017 at 8:53
  • @percusse But the question was about LaTeX not plainTeX. Commented Jun 5, 2017 at 9:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .