47

Images appearing inline aren't always ideally placed relative to the baseline and risers of the text itself, so I frequently find myself doing manual adjustment, by eye, using \raisebox{}{} with a negative first parameter.

My question is whether there is a simple way to get a comparable effect without adjusting the parameter manually against the output in each case.

2
  • What kind of inline images are you using in what kind of situations? Are you maybe use images for symbols? Commented Apr 14, 2011 at 21:15
  • 2
    Finishing typesetting a Manchu-English dictionary. The dictionary is in romanization, but in a few places it is useful to cite the original Manchu script. However, images of actual handwritten Manchu look better than the Manchu fonts (accessible though MonTex). Commented Apr 14, 2011 at 23:45

1 Answer 1

57

Images are added with a zero depth, i.e. they sit on the baseline. It depends very much on the situation (and personal taste) what the "ideal" placement of a particular image is. So no, there is no way to automatically get-it-just-right (TM).

Note that \raisebox allows the use of \height, \depth, \width and \totalheight (=height+depth) which represent the original dimension of the to be raised box. As said, \depth is zero and so \totalheight is identical to \height for images. So if you want all you images to be 10% below the baseline you can use \raisebox{-.1\height}{\includegraphics[...]{...}}.

If you want the images to be as deep as the normal text you can use \dp\strutbox as a reference. The \strutbox contains the depth and height of a \strut. Both together are equal to \baselineskip so about 20% larger than the actual font size. Therefore you might want to use -.8\dp\strutbox. Alternatively you can use a font size relative length in ex. 1ex is about the height of an x.

As always you might want to make a macro for this if you need this more often.

3
  • Ah, very nice -- the use of \height always makes me happy. Thank you! Commented Apr 14, 2011 at 23:45
  • 2
    Another comment: If you want top-aligned images in the figure environment, you can use \begin{figure}\raisebox{-\height}{\includegraphics{img1.png}}\qquad\raisebox{-\height}{\includegraphics{img2.png}}\end{figure}
    – yo'
    Commented May 10, 2012 at 16:34
  • 6
    @tohecz: In the meantime since my answer I published adjustbox which can export the valign key to \includegraphics. It allows for easy vertical alignment and uses the the same internal macros as \raisebox. Commented May 10, 2012 at 22:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .