LaTeX fill image proportionally

share on google plus share on facebook share on twitter share on linkedin share via email

At present it is quite easy in LaTeX to fit an image proportionally to a frame of fixed width and height. However, to fill a frame with that same image is not straightforward…

This is a snippet that fits the image proportionally to the frame:

  \caption{Kakamigahara Crematorium, Japan}

To fill the frame, we first have to import two packages at the start of your document.


followed by this command (developed from this post on StackExchange);

\FPeval{\mywidtha}{     #3*2.845274*#1}
\FPeval{\mywidthb}{ (1-#3)*2.845274*#1}
\FPeval{\myheighta}{    #4*2.845274*#2}
\adjustbox{min size={#1mm}{#2mm},
    Clip*={#3\width - \mywidtha}   {#4\height - \myheighta}
          {#3\width + \mywidthb}  {#4\height + \myheightb}}%           
          {\includegraphics[max size={#1mm}{#2mm}]{#5}}}


The factor 2.84574 converts from mm to pt.
Then, we can use the command to fill a frame. In this case, 60mm width, 40mm height, positioned at 50% of the horizontal and vertical dimensions of the original image.

  \caption{Kakamigahara Crematorium, Japan}

This definition works, but could be further improved to allow any unit for the width and height.
The resulting two types of figures, fitted and filled, will look like this:


Leave a response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>