[Tex/LaTex] Vertical alignment with subfig and pstricks

horizontal alignmentpstrickssubfloatsvertical alignment

I'm working with pstricks to add illustrations to a paper, as I found that it allows me to save much time compared to editing files with dia/xfig/visio/etc. and including pngs.

But I'm having a few issues when I use them in subfigures. My latest issue was with vertically centering my images.

After some time searching mailing lists, forums and blogs, I learned that subfigures should be abandonned, as subfig was much better. And happened to have a neat trick to do vertical centering. An hour later, all my subfigures renamed as subfloats and the vertical spacing fixed when for some reason subfig tried to display images offpage, and here I am, back to my original question of vertically centering one of two subfigures.

My original code :

\begin{figure}[htp!]%
\centering
\subfloat[Caption 1] {%
\begin{pspicture}(5.5,2)
\psframe(0,0)(1.5,1.5)
    %% More pst code
\rput(5.125,0.75){\psscalebox{1}{B\sous{R}}}
\end{pspicture}
}%
\qquad
\vline
\subfloat[Caption 2] {%
\begin{pspicture}(-0.5,0)(5.5,3.5)
\psframe(0,0)(1.5,1.5)
    %% More pst code
    \rput(5.125,2.75){\psscalebox{1}{B\sous{R}}}
\end{pspicture}
}%
\caption{MainCaption}
\label{fig:label_tbd}
\end{figure}

That gives me my two pictures side by side, properly spaced, with the vertical line between them. But the left hand one that is smaller is bottom aligned with the larger one.

Now onto the subfig trick:

\newsavebox{\tempbox}
\begin{figure}[htb!]%
\centering
\sbox{\tempbox}{%
\begin{pspicture}(-0.5,0)(5.5,3.5)
    %% pst code for larger pic
}
\subfloat[Caption 1] {%
\vbox to \ht\tempbox{%
\vfill
    %% Code for my smaller picture
    \vfill}
}%
\qquad
\vline
\subfloat[Caption 2] {%
    \usebox{\tempbox}
}%
\caption{MainCaption}
\label{fig:label_tbd}
\end{figure}

And now my left image is indeed centered, but the images are on two separate lines.
If I remove the \qquad command, they're on the same line, but the left image is in the middle of the page and the right one is 90% out of the page.

Anyone knows how to solve this problem ?

Best Answer

The code should be

\vbox to\ht\tempbox{
  \vfill
  \hbox{code for the picture}
  \vfill}

Notice the \hbox, whithout which LaTeX enters unrestricted horizontal mode and tries to build a paragraph with the current line width.

Related Question