2

I'm trying to make a command that adds images to page in a way that fill the rest of the page. I'm using code from How to define a figure size so that it consumes the rest of a page? and it works. But I noticed that sometimes the image will be very small when there is little space left, so I wanted to make it conditional - if there is more than 1/3 of the page left, fit the image, otherwise just put the bigger image on the next page - but I can't get the if to work. I'm new with LaTeX, can you help me make it work?

Here's the code:

\newcommand\measurepage{\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}
\newcommand{\imgFill}[1]{\begin{center}
\ifnum \measurepage<0.3*\textheigth \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{#1} 
\else \includegraphics[height=\measurepage,width=\textwidth,keepaspectratio]{#1} \fi
\end{center}
}
  • 1
    \measurepage is a dimension not a number, so you need to use \ifdim. Beside this: don't show only snippets, a full document is much easier to test. – Ulrike Fischer Dec 6 '18 at 10:00
1

I've solved it. As Ulrike Fischer said, I should have used ifdim instead of ifnum (like I said, I'm new at this). Also, I had a typo (heigth instead of height)

So, If anyone needs this, working code:

\newcommand\measurepage{\dimexpr\pagegoal-\pagetotal-\baselineskip\relax}
\newcommand{\imgFill}[1]{\begin{center}
\ifdim \measurepage<0.3\textheight \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{#1} 
\else \includegraphics[height=\measurepage,width=\textwidth,keepaspectratio]{#1} \fi
\end{center}
}

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.