# Caption issue when placing figure side by side

I placed 2 figures side by side using the minipage method from this post, and the figures look perfectly fine. However, the caption of the right figure stick out into the margin, why is that and how can I fix it?

My code is like this:

\begin{figure}[htbp]
\centering
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=6.6cm]{figure1.png}
\caption{Caption for figure 1.}
\label{fig:fig1}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=6.6cm]{figure2.png}
\caption{Caption for figure 2, but longer.}
\label{fig:fig2}
\end{minipage}
\end{figure}

• Are you sure you don't want to use the subcaption package along with a subfigure? – Mario S. E. Apr 30 '13 at 9:24
• Please post a minimal working example (MWE). – jub0bs Apr 30 '13 at 9:42
• What you have added is not a minimal example: we don't know the class and possible tweaks to the page setup. – egreg Apr 30 '13 at 18:01
• @egreg, OK, I see what you mean now. The problem is the template package provided by the publisher. I cannot reproduce the issue with the standard graphicx package either. I need to look into the template or maybe it simply doesn't allow me to put them side by side. – LWZ Apr 30 '13 at 18:22

Here's the simplest method to achieve what you want:

\documentclass{article}
\usepackage[demo]{graphicx} % [demo] is just for the example
\begin{document}
\begin{figure}
\centering
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.8\textwidth,height=4cm]{a}
\caption{A not so wide caption}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.8\textwidth,height=4cm]{a}
\caption{A caption that should be wider than the figure, but so wide that it should wrap}
\end{minipage}
\end{figure}
\end{document}


Here it's assumed that the two pictures have the same height, so that correct alignment is obtained for the captions.

• Thanks! Could you explain which line of code makes it to wrap around? I couldn't tell any difference between my code and yours, except I set my image width to absolute value using width=6cm, and yours is width=.8\textwidth. – LWZ Apr 30 '13 at 17:35
• @LWZ I've used the standard methods. Without seeing your code I can't say more. Using an absolute value might create overfull boxes, though: if 6cm is more than .45\textwidth the figure can't be accommodated. – egreg Apr 30 '13 at 17:39
• This is strange. I uploaded my code. I also tried using width=.8\textwidth and it still has the same issue. – LWZ Apr 30 '13 at 17:46

I would suggest you go for the subcaption package, since this is the purpose of it, and do something like this:

\documentclass{article}

\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics[scale=1]{MuscularTissue3_1}
\caption{Skeletal}
\label{fig:SkeletalTissue}
\end{subfigure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics[scale=1]{MuscularTissue3_2}
\caption{Cardiac}
\label{fig:CardiacTissue}
\end{subfigure}
\caption{Two Types of Muscular Tissue}
\label{fig:MuscularTissue}
\end{figure}

If you want to reference the first figure (Figure~\ref{fig:SkeletalTissue}), if you want the second (Figure~\ref{fig:CardiacTissue}).  If you want to reference both (Figure~\ref{fig:MuscularTissue}

\end{document}


I don't have your figures, so I just put some of mine. The output would be something like this:

For more information, please refer to the subfigure documentation

• Thanks for your advice. However in my case I do have two separate figures, and the only reason I put them side by side is to save space. They do not have a common caption. – LWZ Apr 30 '13 at 17:40

I just encountered this problem myself and found the solution I think:

\documentclass{article}
\usepackage[demo]{graphicx} % [demo] is just for the example
\usepackage{caption}
\begin{document}
\begin{figure}[h!]
\centering
\captionsetup{width=0.45\textwidth} % Choose 0.45 to leave some space between captions
\begin{minipage}{0.49\textwidth} % Choose 0.49 to prevent minipages stacking
\centering
\includegraphics[width=0.95\textwidth]{a} % Choose smaller than 1 to have space between figures
\captionof{figure}{Caption text for figure 1 and it is quite long.}\label{fig:figure1}
\end{minipage}
\begin{minipage}{0.49\textwidth} % Choose 0.49 to prevent minipages stacking
\centering
\includegraphics[width=0.95\textwidth]{a} % Choose smaller than 1 to have space between figures
\captionof{figure}{Caption text for figure 2 and it is quite long.}\label{fig:figure2}
\end{minipage}
\end{figure}
\end{document}


Summary: change \caption{caption text} to \captionof{figure}{caption text} and set the width using the 'caption' package.

Regards,

Ernst Jan