set a maximum width and height for an image

You can use the keepaspectratio key and define your graphics as:

\includegraphics[width=10cm,height=10cm,keepaspectratio]{image}

The MWE is as follows:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=2cm,height=3cm,keepaspectratio]{./graphics/amato}
\includegraphics[width=2cm,height=3cm,keepaspectratio]{./graphics/cardtrick}
\end{document}

enter image description here

Experiment with images with different aspect ratios to see the effect.


If you load the package adjustbox with the export option, its keys are usable with \includegraphics: put the following in the preamble

\usepackage[export]{adjustbox} % loads also graphicx

and then use

\includegraphics[max height=<dimension>,max width=<dimension]{file}

In this way the image will be scaled at the maximum size so that its width and its height will not exceed the two stated dimensions and no distortion will be made.


You can use graphicx package as below.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{imagefile.pdf}
\caption{Caption of the figure}
\end{figure}
\end{document}

imagefile.pdf is the filename of your figure file and it can be .png, .jpg......etc.