Discussion:
Figure Alignment, again....
(too old to reply)
Andrew Greensted
2004-08-09 20:58:21 UTC
Permalink
Hi All,

This topic seems to crop up quite regularly, but I've not found any
satisfying solutions amongst the postings (or FAQs).

I'm trying to place two subfigures side by side so that their centers
(top to bottom) are aligned:

+------+
+----+ | |
| | | |
+----+ | |
+------+
a) b)

So far I'm using the markup below, and as it aligns the figures by their
baselines, there bottoms are aligned.

begin{figure}
\centering
\subfigure[]{\includegraphics[clip]{images/diffRespHeart.eps}}
\hspace{3mm}
\subfigure[]{\includegraphics[clip]{images/diffRespSal.eps}}
\caption[Short cap]{Long Cap}
\label{fig:diffResponse}
\end{figure}

I've had a look at \raisebox, and minipages but without success. Surely
there is a nice, elegant and tidy way to do this?

This one is really really driving me nuts. Any help would be very
appreciated.

Cheers
Andy
Ulrike Fischer
2004-08-10 08:36:45 UTC
Permalink
Post by Andrew Greensted
Hi All,
This topic seems to crop up quite regularly, but I've not found any
satisfying solutions amongst the postings (or FAQs).
I'm trying to place two subfigures side by side so that their centers
+------+
+----+ | |
| | | |
+----+ | |
+------+
a) b)
So far I'm using the markup below, and as it aligns the figures by their
baselines, there bottoms are aligned.
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subfigure}

\begin{document}
\begin{figure}
\centering
\subfigure[]{\raisebox{-0.5\height}{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\raisebox{-0.5\height}{\rule{2cm}{4cm}}}
\caption[Short cap]{Long Cap}
\label{fig:diffResponse}
\end{figure}
\end{document}
--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
Andrew Greensted
2004-08-10 09:00:55 UTC
Permalink
Firstly, thanks for the response.

The problem with this approach is that the subfigure labels become
unaligned. They shift with the centred image. What I'm after is for the
figures centres to be aligned, and their captions to also (but
separately) be aligned, like in my little picture:

+------+
+----+ | |
| | | | <- Aligned by centre
+----+ | |
+------+
a) b) <- Also aligned

Thanks,
Andy
Post by Ulrike Fischer
Post by Andrew Greensted
Hi All,
This topic seems to crop up quite regularly, but I've not found any
satisfying solutions amongst the postings (or FAQs).
I'm trying to place two subfigures side by side so that their centers
+------+
+----+ | |
| | | |
+----+ | |
+------+
a) b)
So far I'm using the markup below, and as it aligns the figures by their
baselines, there bottoms are aligned.
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subfigure}
\begin{document}
\begin{figure}
\centering
\subfigure[]{\raisebox{-0.5\height}{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\raisebox{-0.5\height}{\rule{2cm}{4cm}}}
\caption[Short cap]{Long Cap}
\label{fig:diffResponse}
\end{figure}
\end{document}
Ulrike Fischer
2004-08-10 10:20:21 UTC
Permalink
Post by Andrew Greensted
Firstly, thanks for the response.
The problem with this approach is that the subfigure labels become
unaligned. They shift with the centred image. What I'm after is for the
figures centres to be aligned, and their captions to also (but
+------+
+----+ | |
| | | | <- Aligned by centre
+----+ | |
+------+
a) b) <- Also aligned
Then you should give both images the same depth. e.g.:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subfigure}

\begin{document}
\begin{figure}
\centering

\subfigure[]{\raisebox{-0.5\height}[0.5\height][3cm]{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\raisebox{-0.5\height}[0.5\height][3cm]{\rule{2cm}{4cm}}}
\caption[Short cap]{Long Cap} \label{fig:diffResponse}
\end{figure}
\end{document}

And please: don't top post.
--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
Andrew Greensted
2004-08-10 10:39:34 UTC
Permalink
Post by Ulrike Fischer
Post by Andrew Greensted
Firstly, thanks for the response.
The problem with this approach is that the subfigure labels become
unaligned. They shift with the centred image. What I'm after is for the
figures centres to be aligned, and their captions to also (but
+------+
+----+ | |
| | | | <- Aligned by centre
+----+ | |
+------+
a) b) <- Also aligned
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage[ansinew]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subfigure}
\begin{document}
\begin{figure}
\centering
\subfigure[]{\raisebox{-0.5\height}[0.5\height][3cm]{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\raisebox{-0.5\height}[0.5\height][3cm]{\rule{2cm}{4cm}}}
\caption[Short cap]{Long Cap} \label{fig:diffResponse}
\end{figure}
\end{document}
And please: don't top post.
(I assume you mean put my reply below yours)

Although your solution works, having to specify the `extend-below'
amount is not very universal. It would have to be set for each time. Is
there perhaps some length that can be substituted that relates to the
max height of the two boxes.

Thanks again
Andy
Ulrike Fischer
2004-08-10 12:10:04 UTC
Permalink
Post by Andrew Greensted
(I assume you mean put my reply below yours)
Although your solution works, having to specify the `extend-below'
amount is not very universal. It would have to be set for each time. Is
there perhaps some length that can be substituted that relates to the
max height of the two boxes.
You can put both graphics in a temporary box (\newsavebox{\mybox}
\sbox{\mybox}...)

and then use the height (\ht\mybox) of this box.

You can also use \vphantom to get in both subfigure the same vertical
content:

\subfigure[]{\vphantom{\raisebox{-
0.5\height}{\rule{2cm}{4cm}}}\raisebox{-0.5\height}{\rule{2cm}{2cm}}}
--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
Andrew Greensted
2004-08-10 12:51:33 UTC
Permalink
Post by Ulrike Fischer
You can put both graphics in a temporary box (\newsavebox{\mybox}
\sbox{\mybox}...)
and then use the height (\ht\mybox) of this box.
You can also use \vphantom to get in both subfigure the same vertical
\subfigure[]{\vphantom{\raisebox{-
0.5\height}{\rule{2cm}{4cm}}}\raisebox{-0.5\height}{\rule{2cm}{2cm}}}
This is getting beyond the limits of my latex knowledge now. But, here's
what I tried:

begin{figure}
\centering
\newsavebox{\mybox}
\sbox{\mybox}{%
\subfigure[]{\raisebox{-0.5\height}[0.5\height][\ht\mybox]{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\raisebox{-0.5\height}[0.5\height][\ht\mybox]{\rule{2cm}{3cm}}}}
\usebox{\mybox}
\caption[Short cap]{Long Cap}
\label{fig:label}
\end{figure}

The centring is fine, but it renders the captions as if \ht\mybox is
being read as zero. I think that the easiest solution is to start
combining any subfigures into one figure with the subfigure captions as
part of the graphic. Although, so far latex has not beaten me on any
problem, and I don't really want to let it start!!

Andy
Ulrike Fischer
2004-08-10 13:37:53 UTC
Permalink
Post by Andrew Greensted
This is getting beyond the limits of my latex knowledge now. But,
begin{figure}
\centering
\newsavebox{\mybox}
\sbox{\mybox}{%
\subfigure[]{\raisebox{-0.5\height}[0.5\height][\ht\mybox]{\rule{2cm}{2
cm}}} \hspace{3mm}
\subfigure[]{\raisebox{-0.5\height}[0.5\height][\ht\mybox]{\rule{2cm}{3
cm}}}} \usebox{\mybox}
\caption[Short cap]{Long Cap}
\label{fig:label}
\end{figure}
The centring is fine, but it renders the captions as if \ht\mybox is
being read as zero.
Looks like the question what was first the egg or the bird.

You are saving something that uses \ht\mybox in the box \mybox.

So what do you think is the value of \ht\mybox in this moment? The
height of the empty box from \newsavebox or the height of the new box
that hasn't been build yet?


Do something like this:

\newsavebox{\mybox} %in preambel

\begin{figure}
\sbox{\mybox}{\rule{2cm}{2cm}\rule{2cm}{3cm}}

%\ht\mybox is the maximum height of the two rule = 3cm


\subfigure[]{\raisebox{-
0.5\height}[0.5\height][-0.5\ht\mybox]{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\raisebox{-
0.5\height}[0.5\height][-0.5\ht\mybox]{\rule{2cm}{3cm}}}}

\caption[Short cap]{Long Cap}
\label{fig:label}
\end{figure}
--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
Andrew Greensted
2004-08-10 14:31:48 UTC
Permalink
Post by Ulrike Fischer
Looks like the question what was first the egg or the bird.
You are saving something that uses \ht\mybox in the box \mybox.
So what do you think is the value of \ht\mybox in this moment? The
height of the empty box from \newsavebox or the height of the new box
that hasn't been build yet?
\newsavebox{\mybox} %in preambel
\begin{figure}
\sbox{\mybox}{\rule{2cm}{2cm}\rule{2cm}{3cm}}
%\ht\mybox is the maximum height of the two rule = 3cm
\subfigure[]{\raisebox{-
0.5\height}[0.5\height][-0.5\ht\mybox]{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\raisebox{-
0.5\height}[0.5\height][-0.5\ht\mybox]{\rule{2cm}{3cm}}}}
\caption[Short cap]{Long Cap}
\label{fig:label}
\end{figure}
Surely this brings us back the same problem as before. You end up
needing to explicitly specify an image size.

Andy
Lars Madsen
2004-08-10 14:56:21 UTC
Permalink
Post by Andrew Greensted
Post by Ulrike Fischer
Looks like the question what was first the egg or the bird.
You are saving something that uses \ht\mybox in the box \mybox.
So what do you think is the value of \ht\mybox in this moment? The
height of the empty box from \newsavebox or the height of the new box
that hasn't been build yet?
\newsavebox{\mybox} %in preambel
\begin{figure}
\sbox{\mybox}{\rule{2cm}{2cm}\rule{2cm}{3cm}}
%\ht\mybox is the maximum height of the two rule = 3cm
\subfigure[]{\raisebox{-
0.5\height}[0.5\height][-0.5\ht\mybox]{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\raisebox{-
0.5\height}[0.5\height][-0.5\ht\mybox]{\rule{2cm}{3cm}}}}
\caption[Short cap]{Long Cap}
\label{fig:label}
\end{figure}
Surely this brings us back the same problem as before. You end up
needing to explicitly specify an image size.
Andy
This works just fine

\documentclass{article}
\usepackage{subfigure}

\makeatletter
\newcommand\xbox[1]{%
\settowidth\@tempdima{#1}
\parbox[c][\ht\mybox]{\@tempdima}{#1}
}
\makeatother
\newsavebox{\mybox} %in preambel
\begin{document}
\begin{figure}
\centering
\sbox{\mybox}{\rule{2cm}{2cm}\rule{2cm}{3cm}}
\subfigure[]{\xbox{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\xbox{\rule{2cm}{3cm}}}
\caption{caption}
\label{fig:label}
\end{figure}
\end{document}


You will have to insert you figures twice here (instead of the \rule's)

But you could of course make your own macro to do this all at once, if it's
always two figures beside eachother then it's quite easy to make a macro with
four arguments that do

\sbox{\mybox}{\rule{2cm}{2cm}\rule{2cm}{3cm}}
\subfigure[]{\xbox{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\xbox{\rule{2cm}{3cm}}}

automatically
--
/daleif (remove RTFSIGNATURE from email address)

LaTeX FAQ: http://www.tex.ac.uk/faq
AMSMATH Intro: http://www.ams.org/tex/short-math-guide.html
LaTeX Intro: http://people.ee.ethz.ch/~oetiker/lshort/lshort.pdf
Graphics Intro: http://www.ctan.org/tex-archive/info/epslatex.pdf
Superb Class: http://www.ctan.org/tex-archive/help/Catalogue/entries/memoir.html
Remember to post minimal working examples.
Ulrike Fischer
2004-08-11 07:34:11 UTC
Permalink
Post by Andrew Greensted
Post by Ulrike Fischer
\newsavebox{\mybox} %in preambel
\begin{figure}
\sbox{\mybox}{\rule{2cm}{2cm}\rule{2cm}{3cm}}
%\ht\mybox is the maximum height of the two rule = 3cm
\subfigure[]{\raisebox{-
0.5\height}[0.5\height][-0.5\ht\mybox]{\rule{2cm}{2cm}}}
\hspace{3mm}
\subfigure[]{\raisebox{-
0.5\height}[0.5\height][-0.5\ht\mybox]{\rule{2cm}{3cm}}}}
\caption[Short cap]{Long Cap}
\label{fig:label}
\end{figure}
Surely this brings us back the same problem as before. You end up
needing to explicitly specify an image size.
? I only use absolute values in the \rule-commands which are a
replacement of your graphics. If you use \includegraphics only values
relative to the size of your images like \ht\mybox or 0.5\height will
be your code.

Replace every \rule-command which the image it represent and you will
see.
--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
drushka
2004-08-10 14:01:25 UTC
Permalink
Post by Andrew Greensted
The problem with this approach is that the subfigure labels become
unaligned. They shift with the centred image. What I'm after is for the
figures centres to be aligned, and their captions to also (but
Hi Andy, Ulrike,

Besides tweaking the positions of the images manually (which may take
some time till you get it right), a quick-and-dirty way to circumvent
this problem is just to put the figures inside a frameless tabular
environment.
The labels then go into their own tab fields. Figures and labels are
then aligned automatically.

Obviously you lose the nice automatic assignment of subfigure labels
because you have to put them in manually but this seems to me a fair
tradeoff against not having to align things.

Obviously, this is a kludge, so it is only useful for a small number
of subfigures.

Cheers,
Andreas

PS: I use lyx with the odd plain latex source code strewn in. The
whole tabular and figure issue is just a simple matter of
point-and-click for me while it may be illegible in talex source, so
YMMV.
Andrew Greensted
2004-08-10 14:26:13 UTC
Permalink
Post by drushka
Besides tweaking the positions of the images manually (which may take
some time till you get it right), a quick-and-dirty way to circumvent
this problem is just to put the figures inside a frameless tabular
environment.
The labels then go into their own tab fields. Figures and labels are
then aligned automatically.
I had a go with this approach, but I had trouble persuading the tabular
environment to spread itself over the width of the entire page.
That said, this may well be the way to go (but that might be the html
writer in me coming through).

Andy
R. H. Allen
2004-08-10 19:22:49 UTC
Permalink
On Tue, 10 Aug 2004 10:00:55 +0100, Andrew Greensted
Post by Andrew Greensted
Firstly, thanks for the response.
The problem with this approach is that the subfigure labels become
unaligned. They shift with the centred image.
The subfig package supersedes the subfigure package and gives you a bit
more control over how things are aligned. As I recall, it defaults to
aligning the figures along the baselines instead of the centers, but it
might have an option for you to control that. I believe the subfigure
labels are always aligned in the way that you want. It might be worth a
look.

alan
Loading...