[Tex/LaTex] Fill remaining page with image

fillgraphicsvertical

I hope to fill the remaining vertical space with an image. This has been done here; https://blogs.gnome.org/muelli/2011/04/perfectly-scale-an-image-to-the-rest-of-a-page-with-latex/

However I cant figure out how this is done. I am not very used to macros.
I simply hope that something like this exists;

\includegraphics[width=0.7\textwidth,keepaspectratio=true,
                 height= "Vertical space remaining" ]{figure.fig}

Best Answer

You can mark the bases of lines as "labels" using zref's savepos module. This allows you to do calculations on the (x and) y coordinates of the labels. The command \filltopageendgraphics[<options>]{<file>} below automates this process (assuming you'll only have one such image on any given page).

enter image description here

\documentclass{article}

\usepackage{zref-savepos,graphicx}
\usepackage{lipsum}

% \filltopageendgraphics[<options>]{<file>}
\newcommand{\filltopageendgraphics}[2][]{%
  \par
  \zsaveposy{top-\thepage}% Mark (baseline of) top of image
  \vfill
  \zsaveposy{bottom-\thepage}% Mark (baseline of) bottom of image
  \smash{\includegraphics[height=\dimexpr\zposy{top-\thepage}sp-\zposy{bottom-\thepage}sp\relax,#1]{#2}}%
  \par
}

\begin{document}

\lipsum[1]

\filltopageendgraphics[width=.5\linewidth]{example-image-a}

\clearpage

\lipsum[2]

\filltopageendgraphics[width=.6\linewidth]{example-image-b}

\clearpage

\lipsum[1-3]

\filltopageendgraphics[width=.7\linewidth]{example-image-c}

\end{document}
Related Question