I have a lot of figures to put side by side in a document, and they are all slightly different in size (i.e. not all 4:3 format or so).
What I'm doing at the moment is tweak the width=0.XX\textwidth
of both until they look more or less the same height.
Here I provide an example code: what I would like to be able to do is have a macro or something, where I can simply provide the two figures and they automatically scale to have the same height and fit on one line. Is that possible? And if yes, how?
Edit: since people are asking why I'm not providing specific sizes for the images: The code should work with any 2 images with any aspect ratio. Give it two images and the code scales them to fit side by side and have the same height, filling the horizontal space available.
\documentclass{scrreprt}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
\chapter{Figures}
\begin{figure}[h!]
\centering
\subfloat[Figure one]{%
\centering\includegraphics[width=0.45\textwidth]{example-image-a}}
\qquad
\subfloat[Figure two with different side proportions]{%
\centering\includegraphics[width=0.45\textwidth]{example-image-16x9}}
\caption{How to get the two figures to same height (respecting proportions)?}
\end{figure}
\end{document}
What I get:
What I wish to happen automatically:
Best Answer
For the two sample graphs and the default text width and height given by the
scrreprt
document class, it suffices to replacewidth=...
withheight=0.21\textheight
, for bothsubfig
groups.For other combinations of text widths, text heights, and proportions of the pairs of images that need to be placed next to each other, you'll probably have to experiment a bit to find out which value of
height=...
is about right.I'm assuming that the objective is to make the pairs of graphs be as large as possible, i.e., span the full width of the textblock. If this assumption is valid, none of the
\centering
instructions are needed.