I have a script which automatically creates a beamer presentation with several .ps images, each one inserted in a distinct frame. Those images consist on graphs built using GraphViz. The script is basically iterating on this code snippet:
\begin{frame}{Image 1}
\begin{figure}
\includegraphics[width=1\textwidth]{image-1.ps}
\end{figure}
\end{frame}
I have some images with large widths, like this one (reduced the size and quality for best viewing):

So the above code works like a charm. But I do have small images as well, like this one:

If I leave the \includegraphics command with no adjustments, my images will become way bigger than the frame itself. If I put width=1\textwidth, it will work fine with large width images, but not with small ones.
Is there a way to find the best figure size adjustment when using \includegraphics, so my images will be displayed correctly? I usually do that manually, but in this case it's a script which simply adds the image to the .tex body and compile it. I'm pretty sure I'm missing something obvious here, but couldn't figure out what it is.
keepaspectratiois a new one for me. Exactly what I need, too. – Matthew Leingang May 04 '11 at 17:12adjustboxpackage allows to use\adjustbox[width=\linewidth,height=\textheight,keepaspectratio]{<text>}. You might want to usetotalheightinstead ofheight. Alternatievly you can use\resizebox{<width>}{<height>}{<text>}(or\resizebox*to usetotalheightinstead) but this requires\Gin@isotruelocally to enable thekeepaspectratiofeature. You could write is as\csname Gin@isotrue\endcsnameto avoid issues with the@. – Martin Scharrer May 25 '11 at 11:21\begin{figure}[p] \includegraphics[width=\linewidth,height=\textheight,keepaspectratio]{picture} \caption{somecaption} \end{figure}then the graphic will be scaled to fit the page, but the float might still produce anoverfull hboxbecause of the caption. – Janek Jun 20 '13 at 11:27captionpackage to get smarter captions. – Martin Scharrer Jun 20 '13 at 12:59\documentclass[a4paper,10pt]{scrartcl} \usepackage{graphicx} \begin{document} \begin{figure} \centering \includegraphics[width=\textwidth,height=\textheight]{AnyGraphic} \caption{Some random caption.} \end{figure} \end{document}will result in aFloat too large for pagewarning. – Janek Jun 20 '13 at 14:08height=\textheightis the problem. It doesn't leave any space for the caption. Tryheight=\dimexpr\textheight-2\baselineskip-\abovecaptionskip-\belowcaptionskip\relaxinstead. – Martin Scharrer Jun 21 '13 at 11:59