0

I found some solutions for full page images (here and here), but what I am trying to achieve is putting an image in a page that already has text (some headings, for example) and the image should fill all the remaining space (from the headings to the footer).

This page contains a proposed solution, but since there is no example, and what ever I tried gave me errors (Undefined control sequence. ...undbild). Here is what I tried:

\newlength{\textundbildtextheight}

\newcommand{\textundbild}[2]{
\settototalheight\textundbildtextheight{\vbox{#1}}
#1
\vfill
\begin{center}
\includegraphics[width=\textwidth,keepaspectratio=true,height=\textheight-\the\textundbildtextheight]{#2}
\end{center}
\vfill
}

\begin{document}

\chapter{Chapter 1}
\section{Section X}
\textundbild{1cm}{IMAGENAME}

...
\end{document}
jiun
  • 193

1 Answers1

1

This takes a couple of runs for the page locations to be recorded in the aux file.

enter image description here

\documentclass{article}

\usepackage{graphicx}

\def\posA{0}\def\posB{10}
\def\posC{0}\def\posD{10}
\begin{document}


\section{ZZZ}

\begin{center}
  \begin{tabular}{|cc|}
    1&2\\
    3&4
  \end{tabular}
\end{center}

zzzz  zzzz z  z zzzz

\begin{center}

\pdfsavepos\write\csname @auxout\endcsname{\gdef\string\posA{\the\pdflastypos}}
\par
\includegraphics[width=\textwidth,height=\dimexpr\posA sp -\posB sp,keepaspectratio]{example-image-9x16}
\vfill
\pdfsavepos\write\csname @auxout\endcsname{\gdef\string\posB{\the\pdflastypos}}
\end{center}

\clearpage

page 2


\section{ZZZZ}
\begin{center}
  \begin{tabular}{|cc|}
    1&2\\
    3&4\\
    5&6\\
    7&8\\
  \end{tabular}
\end{center}

\section{ZZZZZZ}

\subsection{ZZ}

\begin{center}
  \begin{tabular}{|cc|}
    1&2\\
    3&4\\
    5&6\\
    7&8\\
  \end{tabular}
\end{center}

zzzz  zzzz z  z zzzz

\begin{center}

\pdfsavepos\write\csname @auxout\endcsname{\gdef\string\posC{\the\pdflastypos}}
\par
\includegraphics[width=\textwidth,height=\dimexpr\posC sp -\posD sp,keepaspectratio]{example-image-9x16}
\vfill
\pdfsavepos\write\csname @auxout\endcsname{\gdef\string\posD{\the\pdflastypos}}
\end{center}

\clearpage

page 3
\end{document}
David Carlisle
  • 757,742
  • It works perfectly! Thanks. How about putting it inside a macro (command)? I tried the following but the result is not-resized at all:
    \begin{figure}[H]
    \ifthenelse{\equal{#2}{}}{}{\caption{#2}}
    \centering
    \pdfsavepos\write\csname @auxout\endcsname{\gdef\string\posA{\the\pdflastypos}}
    \par
    \includegraphics[frame,height=\dimexpr\posA sp -\posB sp,keepaspectratio]{#1}
    \vfill
    \pdfsavepos\write\csname @auxout\endcsname{\gdef\string\posB{\the\pdflastypos}}
    \end{figure}
    \clearpage
    }```
    
    – jiun Apr 05 '19 at 22:20
  • @jiun yes sure you could put it in a macro but no point in using figure here as this can not be a floating figure, also the posA and posB macros need to be unique for each figure as they record the position for one figure. – David Carlisle Apr 05 '19 at 22:35
  • I used figure since I want to add a caption. Moreover, I have no idea how to make posA and posB unique for each case (macro usage). I moved the definitions inside the \newcommand environment, but it doesn't work. – jiun Apr 05 '19 at 22:45