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
1  
Use 0.45\textwidth and \hfill between the two subfigure environment. –  egreg May 5 at 18:00

4 Answers 4

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 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 at 19:38

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 at 17:38
    
wasn't aware of that @srao, thanks.. –  Emil May 5 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

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.