1

I have 3 subfloats, but they will not all fit on one line, so I have two in the top row and one on the bottom row. My first problem is the floats are all different sizes and they are not being spaced properly. The captions for all three seem to be in the appropriate spots (bottom float is centered on the page). However, the subfloats seem to be offset to the right in all cases. Also the captions for the first two subfloats are multiline and do not line up the same way. In the first one the second line starts between the (a) and the first letter, in the second subfloat the second line starts indented, about the third letter in. I didn't write this code, so I'm sure there is something in there that is messing it up. Please help me figure out what is going on.

\begin{figure}[h!]
    \centering
    \begin{subfigure}[h]{0.3\textwidth}
            \centering
            \includegraphics[scale=1]{fig_1}
            \caption{This Caption is long and takes two lines}
            \label{fig:fig_1}
    \end{subfigure}%
    \hfill
    \begin{subfigure}[h]{0.3\textwidth}
            \centering
            \includegraphics[scale=1]{fig_2}
            \caption{This Caption is also long and takes two lines}
            \label{fig:fig_2}
    \end{subfigure}

    \begin{subfigure}[h]{0.3\textwidth}
            \centering
            \includegraphics[scale=0.8]{fig_3}
            \caption{Caption Figure 3}
            \label{fig:fig_3}
    \end{subfigure}
    \caption{Caption Figure All}
    \label{fig:all}
\end{figure}
  • 2
    Not having access to the three graphics files -- fig_1, fig_2, and fig_3 -- and not knowing what their natural sizes may be makes it difficult (impossible?) to diagnose the problem properly. Real quick: Rather than using the option [scale=<whatever>], have you tried (i) using the option [width=\linewidth] and (ii) setting the widths of the three subfigure environments to more-or-less adequately influence the sizes of the three graphs? – Mico Apr 19 '13 at 20:27
  • I think that is what I started with and went to scale to change the size, but I went with your suggestion and am modifying the number before \textwidth and am getting much better results. Is there a way to let subfloats overlap (i.e. both have 0.5\textwidth) without them automatically going to separate lines? – Stuart Apr 19 '13 at 20:36
  • 1
    It's probably wise to set the sum of the two subfigure widths to no more than ca. 0.95\textwidth -- and let them be separated by \hfill. (You do want a bit of whitespace between the two side-by-side graphs, right?) Incidentally, if you use the [width=\linewidth] option, you can dispense with the three \centering instructions inside the subfigure environments. – Mico Apr 19 '13 at 20:40
  • BTW: If you want automatic horizontal alignment on the first line of the caption, use \subcaptionbox instead of subfigure environment. – Axel Sommerfeldt Apr 19 '13 at 20:44
  • unrelated to inner positioning but \begin{figure}[h!] is almost always the wrong thing, it explicitly prevents latex from putting the float in almost all the float areas. LaTeX will usually give a warning and change h to ht to give itself a chance but that still prevents p floats and so makes it likely that the float can not be positioned so go to end of document. – David Carlisle Apr 19 '13 at 20:47
0

I switched to [width=\linewidth] instead of [scale=1] and scaled up using the {0.45\textwidth}. This helped keep the floats centered. Because I was using \linewidth I didn't need the \centering commands in the subfigure. I centered the second line of the captions by changing my caption setup. It was set by default to indent second lines at -1. After the \begin{figure} I put in a line \captionsetup{indention=0cm} that only affects this figure.

\begin{figure}[ht!]
    \centering
    \captionsetup{indention=0cm}
    \begin{subfigure}[h]{0.45\textwidth}
            \includegraphics[width=\linewidth]{fig_1}
            \caption{This Caption is long and takes two lines}
            \label{fig:fig_1}
    \end{subfigure}
    \hfill
    \begin{subfigure}[h]{0.45\textwidth}
            \includegraphics[width=\linewidth]{fig_2}
            \caption{This Caption is also long and takes two lines}
            \label{fig:fig_2}
    \end{subfigure}

    \begin{subfigure}[h]{0.4\textwidth}
            \includegraphics[width=\linewidth]{fig_3}
            \caption{Caption Figure 3}
            \label{fig:fig_3}
    \end{subfigure}
    \caption{Caption Figure All}
    \label{fig:all}
\end{figure}

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.