How to display two pictures that have not the same size with the same height?

\documentclass{article}
\usepackage{graphicx}
\newsavebox\IBoxA \newsavebox\IBoxB \newlength\IHeight
\newcommand\TwoFig[6]{% Image1 Caption1 Label1 Im2 Cap2 Lab2
  \sbox\IBoxA{\includegraphics[width=0.45\textwidth]{#1}}
  \sbox\IBoxB{\includegraphics[width=0.45\textwidth]{#4}}%
  \ifdim\ht\IBoxA>\ht\IBoxB
    \setlength\IHeight{\ht\IBoxB}%
  \else\setlength\IHeight{\ht\IBoxA}\fi
  \begin{figure}[!htb]
  \minipage[t]{0.45\textwidth}\centering
  \includegraphics[height=\IHeight]{#1}
  \caption{#2}\label{#3}
  \endminipage\hfill
  \minipage[t]{0.45\textwidth}\centering
  \includegraphics[height=\IHeight]{#4}
  \caption{#5}\label{#6}
  \endminipage 
  \end{figure}%
}

This is how you use it:

\begin{document}

  \TwoFig{methods} % image 1
         {Methods} % caption 1
         {fg:methods} % label 1
         {method_detail} % image 2
         {Method detail information} % caption 2
         {fg:method_detail} % label 2

\end{document}

enter image description here


This compares the heights of the two images and makes the taller one smaller as necessary.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
        \setbox0\hbox{%
                \includegraphics[width=.45\textwidth]{methods}%
        }%
        \setbox2\hbox{%
                \includegraphics[width=.45\textwidth]{methodsdetail}%
        }%
        \ifdim\ht0>\ht2
                \setbox0\hbox{%
                        \includegraphics[height=\ht2]{methods}%
                }%
        \else
                \setbox2\hbox{%
                        \includegraphics[height=\ht0]{methodsdetail}%
                }%
        \fi
        \noindent
        \parbox{.45\textwidth}{%
                \centering
                \unhbox0
                \caption{Methods}
                \label{fg:methods}
        }%
        \hfil
        \parbox{.45\textwidth}{%
                \centering
                \unhbox2
                \caption{Method detail information}
                \label{fg:method_detail}
        }%
\end{figure}
\end{document}

Using some free clipart, without the \if...\fi, it looks like this. enter image description here

With the above code, it looks like this. enter image description here

Tags:

Graphics