blob: 0486039e377d4046a3233456bb5100f18adc8b2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
<head>
<title>UK TeX FAQ -- question label topgraph</title>
</head><body>
<h3>Top-aligning imported graphics</h3>
<p/>When TeX sets a line of anything, it ensures that the base-line of
each object in the line is at the same level as the base-line of the
final object. (Apart, of course, from <code>\</code><code>raisebox</code> commands…)
<p/>Most imported graphics have their base-line set at the bottom of the
picture. When using packages such as <i>subfig</i>, one often
wants to align figures by their tops. The following odd little bit of
code does this:
<blockquote>
<pre>
\vtop{%
\vskip0pt
\hbox{%
\includegraphics{figure}%
}%
}
</pre>
</blockquote><p>
The <code>\</code><code>vtop</code> primitive sets the base-line of the resulting object to
that of the first “line” in it; the <code>\</code><code>vskip</code> creates the illusion
of an empty line, so <code>\</code><code>vtop</code> makes the very top of the box into the
base-line.
<p/>In cases where the graphics are to be aligned with text, there is a
case for making the base-line one ex-height below the top of the box,
as in:
<blockquote>
<pre>
\vtop{%
\vskip-1ex
\hbox{%
\includegraphics{figure}%
}%
}
</pre>
</blockquote><p>
A more LaTeX-y way of doing the job (somewhat inefficiently) uses
the <i>calc</i> package:
<blockquote>
<pre>
\usepackage{calc}
...
\raisebox{1ex-\height}{\includegraphics{figure}}
</pre>
</blockquote><p>
(this has the same effect as the text-align version, above).
<p/>The fact is, <em>you</em> may choose where the base-line ends up. This
answer merely shows you sensible choices you might make.
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=topgraph">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=topgraph</a>
</body>
|