20

I have three images as subfigures. Two images are aligned happily, the first one doesn't line up. All images are the same size (519x346 pixels).

This is what it looks like:

Non-aligned images

I'd like to line up (a) (both image and caption) if possible, the way that (b) and (c) are.
This is the code to produce the currently-seen image:

\documentclass[11pt]{report} 
\usepackage[pdftex, demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\begin{figure}[htbp]
    \centering
    \begin{subfigure}[h]{0.3\textwidth}
        \includegraphics[width=\textwidth]{../Images/GloveOfDoom/RFIDTag_Testing_Side_s}
        \label{rfidtest_xaxis}
        \caption{Testing of the X-axis.}
    \end{subfigure}
    \begin{subfigure}[h]{0.3\textwidth}
        \includegraphics[width=\textwidth]{../Images/GloveOfDoom/RFIDTag_Testing_Vertical_s}
        \caption{Testing of the Y-axis.}
        \label{rfidtest_yaxis}
    \end{subfigure}
    \begin{subfigure}{0.3\textwidth}
        \includegraphics[width=\textwidth]{../Images/GloveOfDoom/RFIDTag_Testing_Other_s}
        \caption{Testing of the Z-axis.}
        \label{rfidtest_zaxis}
    \end{subfigure}
    \caption[RFID tag read-range testing]{RFID tag read-range testing setup. In all tests, the finger moves towards along an axis towards the tag.}
    \label{rfidtag_testing}
\end{figure}
\end{document}
  • The [h] option is unknown and ignored; you should use [b] – egreg Dec 21 '12 at 12:09
  • Just a remark: it shouldn't be necessary to give the graphicx package a pdftex oprtion – Benedikt Bauer Dec 21 '12 at 12:10
26

First, the optional argument to the subfigure environment is the same as for minipage, so t(op), c(enter) or b(ottom), if I remember correctly, and this specifies the "anchor" I think, of the subfigure. Hence, h doesn't do anything.

Second, in the first subfigure you've placed the label before the caption, which creates the extra space between them (exactly why this happens, I'm not sure). The label should always be after or within the caption anyways, to get correct cross references.

Finally, graphicx generally figures out which driver to use on its own, so it's not necessary to specify pdftex (cf. Benedikt Bauer's comment).

enter image description here

\documentclass[11pt]{report} 
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
\begin{figure}[htbp]
    \centering
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{../Images/GloveOfDoom/RFIDTag_Testing_Side_s}
        \caption{Testing of the X-axis.}
        \label{rfidtest_xaxis}
    \end{subfigure}
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{../Images/GloveOfDoom/RFIDTag_Testing_Vertical_s}
        \caption{Testing of the Y-axis.}
        \label{rfidtest_yaxis}
    \end{subfigure}
    \begin{subfigure}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{../Images/GloveOfDoom/RFIDTag_Testing_Other_s}
        \caption{Testing of the Z-axis.}
        \label{rfidtest_zaxis}
    \end{subfigure}
    \caption[RFID tag read-range testing]{RFID tag read-range testing setup. In all tests, the finger moves towards along an axis towards the tag.}
    \label{rfidtag_testing}
\end{figure}
\end{document}
  • 1
    Thanks for the answer, I did solve my problem by substituting \begin{subfigure}{0.3\textwidth} by \begin{subfigure}[b]{0.3\textwidth} – kalmanIsAGameChanger Oct 16 '17 at 15:42
2

The order of your \caption and \label commands is mixed. If you always use:

\includegraphics[]{}
\caption{}
\label{}

the caption to image space is not too big. This works for your example. However, if the captions span over different numbers of lines this is mixed up again.

  • 3
    Welcome to TeX.SX! Perhaps you didn't see that, but I say very much the same in my answer (second paragraph). – Torbjørn T. Oct 26 '15 at 9:11
0

I had this problem with 3 charts, identical axis sizes. Just using subfigures. I discovered that the vertical misalignment was caused by the xlabel values. Two of the charts had the xlabel "elapsed time" and the other one had "x". The word "elapsed" has an ascending "l" and a descending "p", so requires more vertical space than "x". "$x$" is slightly different as well. My not very elegant solution was use \xlabelstye={...at..} to force the xlabel a bit further away from the axis, so that the axes then line up.

Incidentally, the subfigure captions allways seem too far away from the chart itself, so I have to use \vspace{-nnpt} to get separation that looks right.

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.