Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there anyway to avoid what is observed below with the subfigure captions appearing too close together?

I would rather not use the minipage environment as a solution.

\documentclass[]{article}
\usepackage{graphicx}

\usepackage{caption}

\usepackage{subcaption}
\usepackage{subfig}


\begin{document}

\begin{figure}[h!]
  \begin{subfigure}[t]{.5\textwidth}
  \centering
    \includegraphics[width=50mm]{image1.png}
    \caption{Test 1 - text filling out page so it is possible to view the how close the text regions get. I will keep going to show that in the second line.}
  \end{subfigure}%
  \begin{subfigure}[t]{.5\textwidth}
  \centering
    \includegraphics[width=50mm]{image2.png}
    \caption{Test 2 - text filling out page so it is possible to view the how close the text regions get}
  \end{subfigure}
  \caption{Full caption}
\end{figure}

\end{document}

enter image description here

share|improve this question
2  
Use 0.45\textwidth and \hfill between the two subfigure environment. –  egreg May 5 '14 at 18:00

5 Answers 5

up vote 5 down vote accepted

Just use a shorter width for the subfigure:

\documentclass[]{article}
\usepackage[demo]{graphicx} % demo is just for the example

\usepackage{caption}

\usepackage{subcaption}


\begin{document}

\begin{figure}[h!]
  \begin{subfigure}[t]{.45\textwidth}
  \centering
    \includegraphics[width=.9\textwidth]{image1.png}
    \caption{Test 1 - text filling out page so it is possible to view the how close the text regions get. I will keep going to show that in the second line.}
  \end{subfigure}\hfill
  \begin{subfigure}[t]{.45\textwidth}
  \centering
    \includegraphics[width=.9\textwidth]{image2.png}
    \caption{Test 2 - text filling out page so it is possible to view the how close the text regions get}
  \end{subfigure}
  \caption{Full caption}
\end{figure}

\end{document}

Don't load subfig along with subcaption. Also specifying a fixed width like 50mm is not good, because you might exceed the width for the subfigure.

enter image description here

share|improve this answer
    
There appeared to be two copies of the MWE's code; I've taken the liberty of removing the duplicate. –  Mico May 5 '14 at 19:11
    
I see, thanks ever so much for this solution. I had tried .45\textwidth before, but of course forgot to add \hfill to separate them so it didn't appear to be working. –  yorkie1990 May 5 '14 at 19:38
    
This would work, unless you want the figures to be close to each other. I wrote a solution below where I don't change the distance of the figures, and just add padding to the captions. See tex.stackexchange.com/a/246077/37274 –  hadi May 20 at 20:18
    
@hadi To get the images next to each other, just remove the \hfill. –  egreg May 20 at 21:25

You can change the style of the subcaptions using \captionsetup command executed in the preamble of the document.

To change the width of the caption, you would use parameter width as follows (takes 90% of the width of the subfigure).

 \captionsetup[subfigure]{width=0.9\textwidth}

Include this command in the preamble of your document.

Note, that it changes style of subcaptions in the whole document. There are also several other useful parameters you might experiment with (like margin, indent, for more see subfig package documentation http://ctan.org/pkg/subfig, section 3.1.2 ).

Regards.

share|improve this answer
    
\captionsetup may be used locally too, within the figure environment. –  srao May 5 '14 at 17:38
    
wasn't aware of that @srao, thanks.. –  Emil May 5 '14 at 17:51

You could use the \subcaptionbox command from the subcaption package. http://ctan.mirrorcatalogs.com/macros/latex/contrib/caption/subcaption.pdf

\documentclass[]{article}
\usepackage{graphicx}

\usepackage{caption}

\usepackage{subcaption}
%\usepackage{subfig}


\begin{document}

\begin{figure}[h!]
\captionsetup[subfigure]{position=top} %if you want to change the position of the subcaption; default is bottom.
    \subcaptionbox{Test 1 - text filling out page so it is possible to view the how close the text regions get. I will keep going to show that in the second line.\label{subfig-1}}{\includegraphics[width=50mm]{image1.png}}
    \hfill
    %\hspace{1cm}
    \subcaptionbox{Test 2 - text filling out page so it is possible to view the how close the text regions get\label{subfig-b}}{\includegraphics[width=50mm]{image2.png}}
  \caption{Full caption}
\end{figure}

\end{document}
share|improve this answer

Shorter version from original code. Just using \subfloat from \subfig packages.

\documentclass[draft]{article}

\usepackage{graphicx}
\usepackage{subfig}

\begin{document}
\begin{figure}[h!]
    \centering
    \subfloat[Test 1 - text filling out page so it is possible to view the how close the text regions get. I will keep going to show that in the second line.]
        {
            \includegraphics[width=.45\textwidth]{testing.png}
        }
    \qquad
    \subfloat[Test 2 - text filling out page so it is possible to view the how close the text regions get]
        {
            \includegraphics[width=.45\textwidth]{testing.png}
        }
  \caption{Full caption}
\end{figure}
\end{document}

Result:

enter image description here

share|improve this answer

@egreg's answer works, but is more of a work-around than a solution. What if you don't want to decrease the width of your subfigure, and still prevent captions from overlapping?

The simple solution is to call the subfig package with margin options. Like this:

\usepackage[margin=20pt]{subfig}

This will add a nice padding around the sub-figure captions, and prevent them from overlapping. Use whatever margin value that you would like.


Then the following code will produce sub-figures that are adjacent, while keeping their captions properly apart.

\begin{figure}
\centering
\subfloat[This is the first long caption]{
    \includegraphics[width=0.3\textwidth] {fig1.png}%
    \label{fig:f1}
}
\subfloat[This is the second long caption]{
    \includegraphics[width=0.3\textwidth] {fig2.png}%
    \label{fig:f2}
}
\end{figure}

This is the good result with a [margin=20pt]:

Using proper margin value for <code>subfig</code> package


While the bad result (without using the margin option for subfig) would look like this:

Without margin value for <code>subfig</code> package

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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