1

I'm trying to place three images side by side each with its own caption. The code written below works great with the placement of the images, but the captions don't. When compiling it only shows the last caption placed under the first image, and no captions on the other two images. How can i fix this?

The code i've written is this:

\begin{figure}[ht]
\begin{minipage}[b]{0.3\linewidth}
\centering
\includegraphics[width=\textwidth]{image1}
\caption{caption1}
\label{fig:figure1}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.3\linewidth}
\centering
\includegraphics[width=\textwidth]{image2}
\caption{caption2}
\label{fig:figure2}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.3\linewidth}
\centering
\includegraphics[width=\textwidth]{image3}
\caption{caption3}
\label{fig:figure3}
\end{minipage}
\end{figure}
  • 1
    Maybe you are looking for subfigure environment and subcaption package. – JouleV Apr 13 at 17:53
  • Welcome to TeX.SE. Just replace the two \hspace{0.5cm} directives with \hfill and you'll be all set. – Mico Apr 13 at 17:56
  • @Mico - I just tried it, and it still only gives me the one caption on the wrong image. – Anders Thon Sletsjøe Apr 13 at 18:02
  • @AndersThonSletsjøe - Did you replace both instances of \hspace{0.5cm} with \hfill? – Mico Apr 13 at 18:04
  • Yes, @Mico . And I also may have been unclear. I want the images to have its own number. Not like: Figure 1.3 (a) (b) (c) – Anders Thon Sletsjøe Apr 13 at 18:06
1

You're almost there: Just replace both instances of \hspace{0.5cm} with \hspace{\fill} or, more succinctly, \hfill.

While you're at it, you should also delete the three redundant \centering instructions.

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx} % remove 'demo' option in real doc.
\begin{document}

\begin{figure}[ht]
\begin{minipage}{0.3\linewidth}
%\centering  % redundant
\includegraphics[width=\textwidth]{image1}
\caption{caption1}
\label{fig:figure1}
\end{minipage}%
\hfill% not: "\hspace{0.5cm}"
\begin{minipage}{0.3\linewidth}
%\centering  % redundant
\includegraphics[width=\textwidth]{image2}
\caption{caption2}
\label{fig:figure2}
\end{minipage}%
\hfill% not: "\hspace{0.5cm}"
\begin{minipage}{0.3\linewidth}
%\centering  % redundant
\includegraphics[width=\textwidth]{image3}
\caption{caption3}
\label{fig:figure3}
\end{minipage}
\end{figure}
\end{document}
  • Does not seem to work for me. Im using \documentclass{report} – Anders Thon Sletsjøe Apr 13 at 18:11
  • @AndersThonSletsjøe - First off, if one replaces article with report in the code above, all three captions continue to show up as they should. Second, if the solution isn't not working for you, it must be the case that there's something else going on in your document which you haven't revealed so far. Sadly, my psychic skills are absolutely worthless; the chances of me guessing (correctly) what's going on in your document are nil. Please go back to your original posting and edit it in such a way that it (a) becomes compilable and (b) reproduces the problem behavior you wish to solve. – Mico Apr 13 at 18:17
  • Tried changing to article document class, still no luck. Everything else works totally fine. The document compiles with no errors. The problem I have is described in my original post. – Anders Thon Sletsjøe Apr 13 at 18:22
  • 1
    @AndersThonSletsjøe - The code in your posting is a code snippet, i.e., it is not compilable as stated. For instance, it is missing a \documentclass statement, it doesn't load the graphicx package, and it's lacking \begin{document} and \end{document} statements. And because your code is not compilable, it can by definition not generate the problem behavior you wish to fix. In my answer, I made your code snippet compilable by furnishing sensible-looking additions; so far, your attempt at a rejoinder is of the unhelpful "still no luck" variety. What do you expect to happen? – Mico Apr 13 at 18:45
  • 1
    @AndersThonSletsjøe - Suggestion: Edit your query and post the contents of the preamble. – Mico Apr 13 at 19:19
0

Here is a solution using the package subfig:

\documentclass{scrartcl}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}

\begin{figure}[!htb]
 \centering
 \captionabove{Images}%
 \label{fig:images}
 \subfloat[left]{%
      \includegraphics[width=0.25\textwidth]{example-image-a}}
      \label{fig:image-a}
 \qquad
 \subfloat[mid]{%
      \includegraphics[width=0.25\textwidth]{example-image-b}}
      \label{fig:image-b}
 \qquad
 \subfloat[right]{%
      \includegraphics[width=0.25\textwidth]{example-image-c}}
      \label{fig:image-c}
\end{figure}

\end{document}
0

Maybe this solution floatrow will work:

\documentclass{article}
\usepackage[demo]{graphicx} % remove 'demo' option in real doc.
\usepackage{floatrow}

\begin{document}

\begin{figure}[!htb]
\centering %
\floatsetup{floatrowsep=qquad}
\begin{floatrow}[3]%
\ffigbox[\FBwidth]{\caption{caption1}\label{fig:figure1}}{\includegraphics[width=0.3\textwidth]{image1}}
\ffigbox[\FBwidth]{\caption{caption2}\label{fig:figure2}}{\includegraphics[width=0.3\textwidth]{image2}}
\ffigbox[\FBwidth]{\caption{caption3}\label{fig:figure3}}{\includegraphics[width=0.3\textwidth]{image3}}
\end{floatrow}
\end{figure}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.