Top-aligning imported graphics

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 \raisebox commands...)

Most imported graphics have their base-line set at the bottom of the picture. When using packages such as subfig, one often wants to align figures by their tops. The following odd little bit of code does this:

\vtop{%
  \vskip0pt
  \hbox{%
    \includegraphics{figure}%
  }%
}
The \vtop primitive sets the base-line of the resulting object to that of the first "line" in it; the \vskip creates the illusion of an empty line, so \vtop makes the very top of the box into the base-line.

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:

\vtop{%
  \vskip-1ex
  \hbox{%
    \includegraphics{figure}%
  }%
}
The fact is, you may choose where the base-line ends up. This answer merely shows you sensible choices you might make.

This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=topgraph