1

I have two collections of subfigures (produced using the subfig package) that Latex decided to place in opposite pages. I would like to align them to the top of the page but for some reason there's always an extra white space atop the figure in the right page (notice the difference with the red line in the screenshot). I've already checked the images and they are correctly cropped.

misaligned figures

I tried to save and adjust the position of the figures using zref-savepos as explained here but it doesn't seem to do anything. If possible, I would like to align them to the red line. I would also welcome a small explanation about why Latex feels the need to produce that extra white space.

EDIT: As requested I'm adding a MWE:

\documentclass[
    b5paper,
    10pt,
    chapterprefix=on,
    appendixprefix=on,
    numbers=noenddot,
]{scrbook}

\usepackage{scrpage2}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{subfig}
\usepackage[demo]{graphicx}

\begin{document}

\chapter{A Chapter}

\lipsum[1-2]

\begin{figure}%[t]
    \centering

    %\zsaveposy{figa}%
    %\ifnum\zposy{figb}>\zposy{figa} %
    %  \vspace{-\dimexpr\zposy{figb}sp-\zposy{figa}sp}%
    %\fi

    \subfloat[fig1]{
        \includegraphics[width=4.5in, height=1.13in]{fig1}
    }\\
    \subfloat[fig2]{
        \includegraphics[width=2.2in, height=0.82in]{fig2}
    }
    \subfloat[fig3]{
        \includegraphics[width=2.2in, height=0.82in]{fig3}
    }
    \caption{First caption.}

    %\ifnum\zposy{figb}>\zposy{figa} %
    %  \vspace{\dimexpr\zposy{figb}sp-\zposy{figa}sp}%
    %\fi
    %
    \label{fig2a}
\end{figure}

\lipsum[1-2]

\begin{figure}[t] % This [t] is commented out in the real code
    \centering

    %\zsaveposy{figb}%
    %\ifnum\zposy{figa}>\zposy{figb} %
    %  \vspace{-\dimexpr\zposy{figa}sp-\zposy{figb}sp}%
    %\fi

    \subfloat[fig1]{
        \includegraphics[width=2.2in, height=0.82in]{fig1}
    }
    \subfloat[fig2]{
        \includegraphics[width=2.2in, height=0.82in]{fig2}
    }\\
    \subfloat[fig3]{
        \includegraphics[width=2.2in, height=0.82in]{fig3}
    }
    \subfloat[fig4]{
        \includegraphics[width=2.2in, height=0.82in]{fig4}
    }\\
    \subfloat[fig5]{
        \includegraphics[width=2.2in, height=0.82in]{fig5}
    }
    \caption{Second caption.}

    %\ifnum\zposy{figa}>\zposy{figb} %
    %  \vspace{\dimexpr\zposy{figa}sp-\zposy{figb}sp}%
    %\fi
    %
    \label{fig2b}
\end{figure}

\lipsum[1-10]

\end{document}

UPDATE: I answered my own question with a solution to manually fine-tune the alignment in case someone finds it useful later on. I will probably try setting up a bounty later on to see if a better solution comes up.

Moriambar
  • 11,466
  • Can you please provide a minimal, complete version (with the relevant settings used) of the code you are using? – Gonzalo Medina Jul 24 '13 at 21:13
  • @GonzaloMedina I just added a MWE. I tried to reproduce as much as possible the environment of the real document. The measurements of the demo figures are the same as the real ones. – Alberto Miranda Jul 24 '13 at 22:00
  • Try temporarily including the images in an \fbox: \fbox{\includegraphics[width=2.2in, height=0.82in]{fig5}}, for instance, to see the bounding box. You may have to trim a bit from the top of the figure on the right. – egreg Jul 24 '13 at 22:04
  • @egreg as per your suggestion, I've drawn the bounding box for the figures on the right, but this confirms that the extra space appears between the page's top margin and the top of the bounding boxes. Should I reduce the size of the images? – Alberto Miranda Jul 24 '13 at 22:14

1 Answers1

1

I'm answering my own question with a not-so-ideal solution until some other answer comes up.

At the moment, the only method I found that works is manually setting a \vspace*{-.35cm} after the \begin{figure} command. Obviously, this is not perfect since the dimension needs to be fine-tuned for each figure with this problem and I would rather have an automatic solution or, at the least, a way to compute the dimensions of the extra white space latex produces.

\documentclass[
    b5paper,
    10pt,
    chapterprefix=on,
    appendixprefix=on,
    numbers=noenddot,
]{scrbook}

\usepackage{scrpage2}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{subfig}
\usepackage[demo]{graphicx}

\begin{document}

\chapter{A Chapter}

\lipsum[1-2]

\begin{figure}%[t]
    \centering
    \subfloat[fig1]{
        \includegraphics[width=4.5in, height=1.13in]{fig1}
    }\\
    \subfloat[fig2]{
        \includegraphics[width=2.2in, height=0.82in]{fig2}
    }
    \subfloat[fig3]{
        \includegraphics[width=2.2in, height=0.82in]{fig3}
    }
    \caption{First caption.}
    \label{fig2a}
\end{figure}

\lipsum[1-2]

\begin{figure}[t]
    \vspace*{-.35cm} % <-- FIX: manually adjust spacing
    \centering
    \subfloat[fig1]{
        \includegraphics[width=2.2in, height=0.82in]{fig1}
    }
    \subfloat[fig2]{
        \includegraphics[width=2.2in, height=0.82in]{fig2}
    }\\
    \subfloat[fig3]{
        \includegraphics[width=2.2in, height=0.82in]{fig3}
    }
    \subfloat[fig4]{
        \includegraphics[width=2.2in, height=0.82in]{fig4}
    }\\
    \subfloat[fig5]{
        \includegraphics[width=2.2in, height=0.82in]{fig5}
    }
    \caption{Second caption.}
    \label{fig2b}
\end{figure}

\lipsum[1-10]

\end{document}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149