# How to align two images side by side and to scale them automatically to use whole slide?

I have two images. How do I align them side by side and scale them so that both of them together occupy the whole horizontal space in a beamer presentation?

\begin{frame}
\frametitle{Inconsistency}
\begin{itemize}
\item
\begin{center}
\includegraphics[scale=0.3]{peer}
\includegraphics[scale=0.3]{peer-inconsistent}
\end{center}
\end{itemize}
\end{frame}


If vertical size do not matter, then you could use

\includegraphics[width=<X>\textwidth]{<first image>}%
\includegraphics[width=<1-X>\textwidth]{<second image>}


Here <X> denotes a number in (0,1), while <1-X> denotes its complement in the interval (0,1). Note the % to remove any space between the images. For equally-sized images, <X>=<1-X>=.5. Using only width as the scaling dimension will scale the height proportionally, maintaining the aspect ratio.

If vertical size does matter, you can also specify the height.

• why do I get Illegal unit of measure (pt inserted) error? for \includegraphics[width=0.5\textwidth]{peer} Apr 30, 2012 at 21:13
• @user494461: I don't know. You need to provide more context (either in comment, but preferably by editing your original question).
– Werner
Apr 30, 2012 at 21:23
• @user494461: This should work perfectly. Could you check it again. If the issue is still there, please post a full compilable example which causes the issue. Apr 30, 2012 at 22:38
• That works fine for me. However I want to add captions under the images. So I have to use some figure environnement for which your solution does not work. I find minicaption able to do that in beamer. The only problem is that you have two width: the width of the minifigure and the width of the image in the figure so tweaking is needed. Sep 19, 2017 at 20:15
• +1 for the % at the line end. This one gets me again and again. Oct 12, 2020 at 13:25

Just use width=0.5\textwidth instead of scale=3. The width option will scale an image to match the given width while keeping the aspect ratio.

To get a little white space between them you may use something like this.

\begin{figure}
\includegraphics[width=0.475\textwidth]{peer}
\hfill
\includegraphics[width=0.475\textwidth]{peer-inconsistent}
\end{figure}


If you want to add captions to it, I suggest:

\begin{frame}{Pixelweise Segmentierung}
\begin{figure}[ht]
\begin{minipage}[b]{0.45\linewidth}
\centering
\includegraphics[width=\textwidth]{a.png}
\caption{Label for a}
\label{fig:a}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.45\linewidth}
\centering
\includegraphics[width=\textwidth]{b.png}
\caption{Label for b}
\label{fig:b}
\end{minipage}
\end{figure}
\end{frame}


\setbeamertemplate{caption}{\raggedright\insertcaption\par}


to prevent the prefix "Figure" (source).

You can use the columns enviroment:

\begin{frame}
\frametitle{Incosistency}
\begin{columns}[c]
\column{.5\textwidth}
\begin{center}
\includegraphics[scale=0.3]{peer}
\end{center}
\column{.5\texwidth}
\begin{center}
\includegraphics[scale=0.3]{peer-inconsistent}
\end{center}
\end{columns}

\end{frame}

• This won't scale the images to the required size. Apr 30, 2012 at 22:37
• I had wrongly interpreted the question, my bad. May 1, 2012 at 12:04
• There's a small typo. Replace 'texwidth' by 'textwidth' ;-) Jan 23, 2021 at 9:06