[Tex/LaTex] Putting two figures side by side

graphics

\begin{minipage}{0.5\textwidth}
\centering
\includegraphics[width=3cm]{Vlieger} 
    \caption{Vlieger}
    \label{fig1:}
\includegraphics[width=3cm]{Pijl}
    \caption{Pijl}
    \label{fig2:}
\end{minipage}

This is my code to put my two images next to each other. But it doesn't work… Can someone pleas help me?

Best Answer

As Mico suggest, probably you want to make a figure environment, where you can have two figures with two captions using minipages or subfigures environments with two subcaptions ans a main caption. Note that figure environments are floats, so by default they can be moved to the top or bottom of the page, or to another page, although you can influence the position of float environments.

In any case, in these environments and the images usually is better set relative lengths as \linewidth instead of absolute lengths as 3cm.

On the other hand, at least for big images, instead of \centering (and some spacer between the minipages or the subfigures) you may want these aligned with the margins, no matter its exact size. For this, use \hfill as in this minimal working example:

mwe

\documentclass{article}
\usepackage{graphicx} 
\usepackage{subcaption} %  for subfigures environments 
\begin{document}
% Side by side subfigures 
\begin{figure}
\begin{subfigure}[h]{0.4\linewidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{Image A}
\end{subfigure}
\hfill
\begin{subfigure}[h]{0.4\linewidth}
\includegraphics[width=\linewidth]{example-image-b}
\caption{Image B}
\end{subfigure}%
\caption{This is a figure with two subfigures}
\end{figure}
% Side by side figures 
\begin{figure}
\begin{minipage}[c]{0.4\linewidth}
\includegraphics[width=\linewidth]{example-image-a}
\caption{Image A}
\end{minipage}
\hfill
\begin{minipage}[c]{0.4\linewidth}
\includegraphics[width=\linewidth]{example-image-b}
\caption{Image B}
\end{minipage}%
\end{figure}
\end{document}