Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to vertically center two subfigures?

8,366 views
Skip to first unread message

Uli

unread,
Jan 30, 2008, 10:36:28 AM1/30/08
to
Hi all,

am trying to put two figures side by side like the following:
---------------
--------------- | |
| | | |
| | | |
| | | |
--------------- | |
---------------
(1) xxx (2) yyy
Figure 1 xxx and yyy is something

that is the left figure is smaller than the right and both figures shall
be vertically aligned but keeping the caption also on the same bottom
line, ...

using the following packages:
\usepackage[dvips]{graphicx}
\usepackage{subfigure}
\usepackage{psfrag}

Well, I searched a lot the net, but I couldn't find any answer to my
problem. The psfrag is not important for the example, but maybe someone
has an idea together with this package?!
Here is the code which aligns both figures vertically at the bottom
which is default.

\begin{figure}
\centering
\begin{minipage}[b]{7cm}
\centering
\subfigure[xxx]
{
\label{xxx}
\begin{psfrags}%
\psfragscanon%
\resizebox{6.5cm}{!}{\includegraphics{xxx.eps}}%
\end{psfrags}%
}
\end{minipage}%
\begin{minipage}[b]{7cm}
\subfigure[yyy]
{
\label{yyy}
\begin{psfrags}%
\psfragscanon%
\resizebox{6.5cm}{!}{\includegraphics{yyy.eps}}%
\end{psfrags}%
}
\end{minipage}
\caption{xxx and yyy is something.}%
\label{fig:xxx_yyy}
\end{figure}

I have successfully put two figure next to each other. But to vertically
align only the figures itself without the sub-captions I couldn't
manage. I tried a lot with \vspace and an extra minipage.

Any solutions? Thanks in advance!

uli


--

remove 'NOSPAM_' from emailadress for reply

Werner Grundlingh

unread,
Jan 30, 2008, 1:32:25 PM1/30/08
to

For a start, the subfigure package is superseded by the subfig package
for allowing multiple subfloats within a float. Hence, use
\usepackage{subfig}
instead. Of course, I don't know how many subfigures you have in your
document, and how long it may take to remove all such instances.
However, for verification, read the CTAN entry or download the package/
documentation from
http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=subfig

This is how I align two subfigures vertically within a floating
(figure) environment:

\usepackage{subfig,calc,graphicx}

...

\begin{figure}[ht]
\setbox1=\hbox{\includegraphics{xxx.eps}}% The smaller image
\setbox2=\hbox{\includegraphics{yyy.eps}}% The larger image
{\,} \hfill
\subfloat[xxx]{%
\raisebox{0.5\ht2-0.5\ht1}{\includegraphics{xxx.eps}}} \hfill
\subfloat[yyy]{%
\includegraphics{yyy.eps}} \hfill
{\,}


\caption{xxx and yyy is something}

\end{figure}

...

You'll notice that I use boxes to store the images, and then I'm able
to use \ht1 and \ht2 to find the height of the boxes. The calc package
allows for algebraic expressions/calculations in the argument of
\raisebox{...}{...} to raise it just enough to be vertically centered.
The \hfills are just to horisontally centre the figures in the
floating (figure) environment.

Hope this helps,
Werner

Uli

unread,
Jan 30, 2008, 3:53:51 PM1/30/08
to
Werner Grundlingh schrieb:
> [...]


Hi Werner,

thanx for your feedback. Yepp, I remember that the package is obsolete
and that I had a look to the new one some time ago. But for some reason
I didn't change it in the beginning of my document. I guess I thought
that I don't need to since I used subfigure in the past quite often and
succesfully.

Mh, my document has now more than 100 pages. I don't think that I will
change it for this rather minor reason of vertical centering in one
single case. But I will have again a look to your link and your example.
Thanx again.

Some idea to fix this with the subfigure-package?

br, uli

Werner Grundlingh

unread,
Jan 30, 2008, 5:05:19 PM1/30/08
to
On Jan 30, 12:53 pm, Uli <NOSPAM_u...@ich-will-net.de> wrote:
>
> Hi Werner,
>
> thanx for your feedback. Yepp, I remember that the package is obsolete
> and that I had a look to the new one some time ago. But for some reason
> I didn't change it in the beginning of my document. I guess I thought
> that I don't need to since I used subfigure in the past quite often and
> succesfully.
>
> Mh, my document has now more than 100 pages. I don't think that I will
> change it for this rather minor reason of vertical centering in one
> single case. But I will have again a look to your link and your example.
> Thanx again.
>
> Some idea to fix this with the subfigure-package?
>
> br, uli
>
> --
>
> remove 'NOSPAM_' from emailadress for reply

Uli,

Although I have not tried it, I am sure my suggested code will work to
vertically align your images even when using the subfigure package.
Try it and let the rest of the group know...

Of course there is another alternative: You change the bounding box of
the smaller image to include some 'vertical' white space so that it is
shifted vertically to the correct position. This should not be that
difficult if the bounding boxes to both images are tight...

Werner

Uli

unread,
Jan 30, 2008, 7:43:44 PM1/30/08
to
Werner Grundlingh schrieb:

> On Jan 30, 12:53 pm, Uli <NOSPAM_u...@ich-will-net.de> wrote:
>> [...]

>
> Uli,
>
> Although I have not tried it, I am sure my suggested code will work to
> vertically align your images even when using the subfigure package.
> Try it and let the rest of the group know...
>
> Of course there is another alternative: You change the bounding box of
> the smaller image to include some 'vertical' white space so that it is
> shifted vertically to the correct position. This should not be that
> difficult if the bounding boxes to both images are tight...
>
> Werner

Hi Werner!

Yess, you're right. The \raisebox term makes it! I didn't try your lines
yet, so I didn't notice it. Thanx for pointing to your code again.

The problem to figure out how to really center the smaller figure in the
middle is now another topic - not so difficult. Resizing the bounding
box was of course another possibility, but I automatically generate my
eps-figures and I didn't want to change the generator for this exception.

great!

_uli


The solution with subfigure now looks like (without labels and psfrag):

\begin{figure}
\centering
\begin{minipage}[b]{7cm}
\centering
\subfigure[xxx]
{

\raisebox{ 20mm }{ % <-- 5mm just for an example


\resizebox{6.5cm}{!}{\includegraphics{xxx.eps}} }
}

\end{minipage}%
\begin{minipage}[b]{7cm}
\subfigure[yyy]
{

\resizebox{6.5cm}{!}{\includegraphics{yyy.eps}}
}

\end{minipage}
\caption{xxx and yyy is something.}%

\end{figure}

Uli

unread,
Jan 30, 2008, 7:56:10 PM1/30/08
to
also the calculation term works and perfectly does what I wants:

> The solution with subfigure now looks like (without labels and psfrag):
>
> \begin{figure}

\setbox1=\hbox{\includegraphics[keepaspectratio=true]{xxx}}
\setbox2=\hbox{\includegraphics[keepaspectratio=true]{yyy}}

> \centering
> \begin{minipage}[b]{7cm}
> \centering
> \subfigure[xxx]
> {

\raisebox{ 0.5\ht2-0.5\ht1 }{

> \resizebox{6.5cm}{!}{\includegraphics{xxx.eps}} }
> }
> \end{minipage}%
> \begin{minipage}[b]{7cm}
> \subfigure[yyy]
> {
> \resizebox{6.5cm}{!}{\includegraphics{yyy.eps}}
> }
> \end{minipage}
> \caption{xxx and yyy is something.}%
> \end{figure}
>


thanx, uli

Paweł Olejnik

unread,
Mar 3, 2023, 9:27:44 AM3/3/23
to
Use negative trim from the bottom in the smallest subfigure's environment to move a figure up.

\includegraphics[scale=...,trim={0 -1cm 0 0},clip]{....eps}
0 new messages