15

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.

12

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

\documentclass[10pt]{article}
\newdimen\spaceleft
\spaceleft=\textheight
\multiply\spaceleft by -1
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\advance\spaceleft by \pagetotal
\multiply\spaceleft by -1
\typeout{Space on last page:}
\showthe\spaceleft
\end{document}

The result of this is:

Space on last page:

204.0pt.

| improve this answer | |
  • Instead of multiplying something by -1 twice you can simply write \advance\spaceleft by-\pagetotal. – wipet Jun 5 '17 at 8:40
7

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

\documentclass{article}
\usepackage{lipsum}

\begin{document}
\lipsum[1-3]

\newdimen\spaceleft
\spaceleft=\dimexpr\textheight-\pagetotal\relax

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

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.