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.

This is an extension of the question "How to ensure that 2 couples of figures are on 2 facing pages?". I not only want to ensure that the figures are on facing pages but also that the one with the smaller height is aligned to the one with the larger height. The latter should be centered on the page. The following example should explain the problem:

\documentclass{book}
\usepackage{dpfloat}
\usepackage[demo]{graphicx}

\begin{document}

Some Text

\begin{figure}
  \begin{leftfullpage}
    \centering
    \includegraphics[width=5cm,height=3cm]{inserthere}
    \caption{This is the short caption.}
  \end{leftfullpage}
\end{figure}

\begin{figure}
  \begin{fullpage}
    \centering
    \includegraphics[width=5cm,height=3cm]{inserthere}
    \caption{This second caption does not only look larger, it actually is,
      by one line.}
  \end{fullpage}
\end{figure}

\end{document}

results innot aligned figures

I would like that figures 2 stays at the same place (centered on the page) but figure 1 moves up a bit so that the top of the two figures are aligned as well as the beginning of the captions.

share|improve this question
    
you could "force" the short caption to be two lines with a \\ \mbox{ }. (if you have a list of figures, you'd have to provide alternate text for that list with the optional argument to \caption, omitting the extra stuff.) –  barbara beeton Oct 2 '12 at 15:50
    
@barbarabeeton This does not seem to work. Without an optional argument for the list of figures, a Argument of \@caption has an extra } is produced. With optional argument, the document compiles find but the \\ seems to be ignored in the caption. Only with the caption package, an additional line is produced but apparently only if there is something visible after the newline. \mbox{ } did not work. –  sebschub Oct 2 '12 at 16:17
    
what if, instead of \mbox{ } you used a rather substantial \phantom{...}? –  barbara beeton Oct 2 '12 at 17:26
    
@barbarabeeton I also tried this one. While apparently this is taken into account by moving the caption to the left (due to invisible longer line length), the vertical placement only changes slightly and not as I want it. –  sebschub Oct 2 '12 at 17:36
2  
one more, somewhat outrageous, suggestion. add a \vphantom{...} with a depth equal to the baselineskip of the font used in the caption. put it right at the beginning, so it doesn't affect the centering of the short caption text, and add the alternate text for the list of figures. or ... what about simply adding a \vspace{1\baselineskip} after, and outside, the caption. –  barbara beeton Oct 2 '12 at 18:35
show 3 more comments

2 Answers 2

up vote 5 down vote accepted

The TeX compilers pdfTeX/LuaTeX (both DVI and PDF) and XeTeX provide a feature for position tracking. Because the final position is not known until the page is shipped out, two LaTeX runs are needed. Package zref-savepos (from package zref) provides an interface to the feature. At the beginning of the floats the vertical position is stored. Then the positions of the two images are compared and the smaller image is shifted. The shifting is redone at the end of the figure. Then LaTeX thinks, the float has still the same height as before and will not change the position of the figure on the page that also would move the saved vertical position at the beginning of the float.

\documentclass[12pt]{book}
\usepackage{dpfloat}
\usepackage[demo]{graphicx}

\usepackage{zref-savepos}
\providecommand*{\zsaveposy}{\zsavepos}% support older zref-savepos

\begin{document}

Some Text

\begin{figure}
  \begin{leftfullpage}
    \centering
    \zsaveposy{figa}%
    \ifnum\zposy{figb}>\zposy{figa} %
      \vspace{-\dimexpr\zposy{figb}sp-\zposy{figa}sp}%
    \fi
    \includegraphics[width=5cm,height=3cm]{inserthere}
    \caption{This is the short caption.}
    \ifnum\zposy{figb}>\zposy{figa} %
      \vspace{\dimexpr\zposy{figb}sp-\zposy{figa}sp}%
    \fi
  \end{leftfullpage}
\end{figure}

\begin{figure}
  \begin{fullpage}
    \centering
    \zsaveposy{figb}%
    \ifnum\zposy{figa}>\zposy{figb} %
      \vspace{-\dimexpr\zposy{figa}sp-\zposy{figb}sp}%
    \fi
    \includegraphics[width=5cm,height=3cm]{inserthere}
    \caption{This second caption does not only look larger, it actually is,
      by one line.}
    \ifnum\zposy{figa}>\zposy{figb} %
      \vspace{\dimexpr\zposy{figa}sp-\zposy{figb}sp}%
    \fi
  \end{fullpage}
\end{figure}

\end{document}

Result

share|improve this answer
    
Thank you. While I prefer your answer (and therefore accepted it), I also like Andrew's and awarded him the bounty to help him reach 3000. –  sebschub Oct 7 '12 at 14:28
add comment

You can redefine the caption building command so that the captions have zero height.

\documentclass{book}
\usepackage[a6paper,margin=10pt]{geometry}
\usepackage{dpfloat}
\usepackage[demo]{graphicx}

\makeatletter
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1: #2}%
  \ifdim \wd\@tempboxa >\hsize
    \vbox to 0pt{#1: #2\par\vss}
  \else
    \vbox to 0pt{\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}\vss}%
  \fi
  \vskip\belowcaptionskip}
\makeatother

\begin{document}

Some Text

\begin{figure}[p]
  \begin{leftfullpage}
    \centering
    \hrule
    \includegraphics[width=5cm,height=3cm]{inserthere}
    \hrule
    \caption{This is the short caption.}
  \end{leftfullpage}
\end{figure}

\begin{figure}[p]
  \begin{fullpage}
    \centering
    \hrule
    \includegraphics[width=5cm,height=3cm]{inserthere}
    \hrule
    \caption{This second caption does not only look larger, it
    actually is, by one line more.}
  \end{fullpage}
\end{figure}

\end{document}

Sample output

Enclose the redefinition in a local group including the figures to affect only these captions.

Of course you may want to regard the caption as having a different height. The following sets up an environment fixedheightcaptions within which all captions have a definable height, default 0pt.

\documentclass{book}
\usepackage[a6paper,margin=10pt]{geometry}
\usepackage{dpfloat}
\usepackage[demo]{graphicx}

\makeatletter
\newlength{\@fcaptionheight}
\long\def\@makefixedcaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{#1: #2}%
  \ifdim \wd\@tempboxa >\hsize
    \vbox to \@fcaptionheight{#1: #2\par\vss}
  \else
    \vbox to \@fcaptionheight{\hb@xt@\hsize{\hfil\box\@tempboxa\hfil}\vss}%
  \fi
  \vskip\belowcaptionskip}

\newenvironment{fixedheightcaptions}[1][0pt]{\setlength{\@fcaptionheight}{#1}
\let\@makecaption\@makefixedcaption}{}

\makeatother

\begin{document}

Some text.

\begin{figure}[h]
  \centering
  \hrule
  \caption{Test caption, normal}
\end{figure}

Some text.

\begin{fixedheightcaptions}[5cm]
  \begin{figure}[h]
    \centering \hrule
    \caption{Test caption of height 5cm}
  \end{figure}
\end{fixedheightcaptions}

Some text.

\begin{fixedheightcaptions}
  \begin{figure}[p]
    \begin{leftfullpage}
      \centering \hrule
      \includegraphics[width=5cm,height=3cm]{inserthere}
      \hrule
      \caption{This is the short caption.}
    \end{leftfullpage}
  \end{figure}

  \begin{figure}[p]
    \begin{fullpage}
      \centering \hrule
      \includegraphics[width=5cm,height=3cm]{inserthere}
      \hrule
      \caption{This second caption does not only look larger, it
      actually is, by one line more.}
    \end{fullpage}
  \end{figure}
\end{fixedheightcaptions}
\end{document}

Here is the first page of output:

First page of output

share|improve this answer
add comment

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.