1

In order to solve this question:

Wrap automatically into figure if not enough space to place it Here

I need to learn the remaining space on the current page.

I tried this to put a rule of exactly the good size, however this rule is pushed on the next page. Any idea why, and how I could know precisely the remaining available space?

If this is not possible, at least is there a way to have a (not too bad) lower bound, so that I'm guaranteed that the rule won't be pushed on next page? Or maybe I can add some penalty to help the rule to stay on this page?

\documentclass{article}

\usepackage{lipsum} \usepackage{showframe}

\begin{document}

\lipsum[1-3]

\edef\measurepage{\the\dimexpr\pagegoal-\pagetotal\relax} % \rule{1mm}{\measurepage}

\end{document}

tobiasBora
  • 8,684

1 Answers1

1

enter image description here

\rule is latex LR box so starts a new paragraph so starts \baselineskip (or as the rule is tall, \lineskip) below the point that you measured. You can suppress that with \nointerlineskip You may also want to account for the depth below the final baseline so

\documentclass{article}
\usepackage{lipsum}
\usepackage{showframe}
\begin{document}
\lipsum[1-3]
\showoutput
\showboxdepth4

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

\nopagebreak\nointerlineskip \rule[-\dp\strutbox]{1mm}{\measurepage}

\end{document}

David Carlisle
  • 757,742
  • @tobiasBora --- If only I could predict the lottery numbers with this level of accuracy. – Ian Thompson Oct 01 '21 at 16:28
  • @IanThompson :-) – David Carlisle Oct 01 '21 at 16:33
  • note that this doesn't take account of stretch or shrink on the page, nor of floats that may be inserted by latex later on during the page make up. If a figure will be inserted at the top of thie page, it won't show up yet in \pagetotal – David Carlisle Oct 01 '21 at 19:45
  • Thanks for your answer. I have 3 follow up questions: 1) why do I need to add the depth below the rule? (intuitively what is important is height+depth, so changing the depth without changing height+depth seems not important... but it is since otherwise rule is pushed on next line. 2) how can I measure the height+depth of a (potentially multilines) content, including the baselineskip/lineskip that could be added by the text? 3) where could I find myself all these informations about the internals of Tex/LaTeX? Is there a famous reference available online? – tobiasBora Oct 01 '21 at 19:54
  • @DavidCarlisle really, floats are not counted? O_o looks annoying since it can heavily change the repartition on a given page... making this solution impossible to use in my problem. So how could I check if a content can fit on the current page to solve my initial problem ? https://tex.stackexchange.com/questions/617306/wrap-automatically-into-figure-if-not-enough-space-to-place-it-here/617341#617341 – tobiasBora Oct 01 '21 at 19:55
  • @tobiasBora it's probably best you can do in a single pass otherwise you need to use \pdfsavepos and pick up exact measurements from the previous run – David Carlisle Oct 01 '21 at 19:59