6

I have two images inside a minipage, so I can have them side by side. When I make a caption for the images it only comes up as "figure 3: text", but I would like to have it showing "Figure 3 & 4: text".

I tried to \end{figure} and \begin{figure} in each minipage but the images would not show side by side anymore. The code I have at the moment is:

\begin{figure}[h]
\begin{minipage}[h]{0.3\textwidth}
\includegraphics[scale=0.58]{fig1}
\end{minipage} \hspace{0.2\textwidth}
\begin{minipage}[h]{0.3\textwidth}
\includegraphics[scale=0.58]{fig2}
\end{minipage}
\caption{text}
\end{figure}
1
  • 1
    You don't need the minipage there you can just use two \includegraphics May 20, 2013 at 23:28

2 Answers 2

6

This isn't quite what you've asked for, but how about the following? I'm using the subcaption package to put your two pictures into two 'subfigures'. The pictures can then be referenced individually (Figure 1a and Figure 1b), or as a pair (Figure 1).

Code

\documentclass{article}

\usepackage{subcaption}
\usepackage[demo]{graphicx}

\begin{document}

\begin{figure}[h]
    \begin{subfigure}{0.3\textwidth}
        \includegraphics[scale=0.58]{fig1}
        \caption{horse}
        \label{fig:horse}
    \end{subfigure} \hspace{0.2\textwidth}
    \begin{subfigure}{0.3\textwidth}
        \includegraphics[scale=0.58]{fig2}
        \caption{zebra}
        \label{fig:zebra}
    \end{subfigure}
\caption{animals}
\label{fig:animals}
\end{figure}

Figure~\ref{fig:animals} shows some animals. Figure~\ref{fig:horse} shows a horse.

\end{document}

Result

enter image description here

1
  • Unfortunately, some conference templates explicitly throw an error when subcaption is loaded. People have to use minipage.
    – yujaiyu
    Aug 9, 2019 at 20:49
1
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\newcounter{dummy}
\begin{document}

\begin{figure}[!h]
\centering
  \includegraphics[scale=0.58]{fig1}
\caption{text}
\end{figure}

\begin{figure}[!h]
\centering%
\begin{minipage}{0.3\textwidth}
  \includegraphics[width=\linewidth]{fig1}
\end{minipage}%
\hspace{0.2\textwidth}%
\begin{minipage}{0.3\textwidth}\centering
  \includegraphics[width=\linewidth]{fig2}
\end{minipage}%
  \renewcommand\thefigure{\arabic{figure} \& %
  \setcounter{dummy}{\arabic{figure}}%
  \protect\stepcounter{dummy}\arabic{dummy}}%
\caption{text}
\stepcounter{figure}%
\end{figure}

\begin{figure}[!h]
\centering
  \includegraphics[scale=0.58]{fig1}
\caption{text}
\end{figure}

\end{document}

enter image description here

3
  • Thanks a lot, it works perfectly. Despite of working fine, there is an error which says "Undefined control sequence \caption{". I tried to play with the packages and see if there was a crash between them, but so far no luck. Do you know why is it showing this error? Thanks once again.
    – user30975
    May 20, 2013 at 14:22
  • difficult to say. A \caption command is defined in nearly all documentclasses
    – user2478
    May 20, 2013 at 15:15
  • I'd refresh very old question. To eliminate the error from Herbert's answer, you also need to protect \setcounter: \renewcommand\thefigure{\arabic{figure} \& % \protect\setcounter{dummy}{\arabic{figure}}% \protect\stepcounter{dummy}\arabic{dummy}}% Dec 1, 2017 at 12:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .