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.

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 ?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
Perfect, you just saved me a second package migration, thank you ! –  Lexiel May 31 '11 at 21:53

A better alternative for subfig is the subcaption package (See subcaption vs. subfig); you can use the subfigure environment and control the vertical alignment using the optional argument whose values are similar to those for a minipage (i.e. t,b, and c). A little example:

\documentclass{book}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{pstricks}

\newcommand\sous[1]{#1}% just to make the example code compilable

\begin{document}

\begin{figure}[htp!]%
\begin{subfigure}[c]{.5\textwidth}
  \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}
  \caption{Test subfigure one}
  \label{fig:sub1}
\end{subfigure}%
\vline
\begin{subfigure}[c]{.5\textwidth}
  \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{Test subfigure one}
  \label{fig:sub2}
\end{subfigure}%
\caption{MainCaption}
\label{fig:label_tbd}
\end{figure}


\end{document}
share|improve this answer
    
I don't really want to change all my subfigures a second time today... But thanks, I'll make sure to use that package for future papers :) –  Lexiel May 31 '11 at 21:35

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.