9
\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?

J. Idk
  • 91
  • Welcome to TeX.SE. How wide is the text block? You're restricting the minipage to have width 0.5\textwidth, while each graphic is given a width of 3cm. If 6cm exceeds 0.5\textwidth, the two graphics simply won't fit in the available space. – Mico Dec 13 '15 at 08:49
  • 1
    Incidentally, is the minipage embedded in a figure environment? The reason I ask is that you're using \caption statements, which generally don't work outside of figure and table environments. – Mico Dec 13 '15 at 08:50

2 Answers2

21

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}
Fran
  • 80,769
  • 3
    For everyone who is coming here and the code isn't working because subfigures is outdated: Refer to the last paragraph of this Overleaf help article https://www.overleaf.com/learn/latex/Errors/Illegal_unit_of_measure_(pt_inserted) and replace \usepackage{subfigures} by \usepackage{subcaption} – Johannes Jul 01 '20 at 17:44
  • For some reason I get only the caption only for Image B, and it appears under Fig A. Any idea? – ScienceFriction Dec 12 '23 at 13:42
  • @ScienceFriction With my TeX LIve 2023 updated just now, I still obtain with the MWE as is, the same result that eight years ago, no matter if I use pdflatex, xelatex or lualatex. Therefore no, I no have idea of your problem, but chances are that you are not compiling the MWE as posted here, or that you have some problem with your LaTeX installation. – Fran Dec 12 '23 at 23:34
0

@ScienceFriction, I don’t know if it will help, but I noticed that if you want to put image side by side in subfigure environment, you have to add a % symbol just after (in the same line) the first \end{subfigure}. If you delete this symbol, figures (still in subfigure environment) will be placed one below the other.