Wednesday, 21 August 2013

Vertically center image with text midpoint

Vertically center image with text midpoint

I want to vertically align the center of an image with the vertical center
of the text on the same line using \raisebox. Using a macro is a must
since it will be used many times (and multiple times on the same line).
This implementation works, but requires the use of temporary lengths. I'd
like to do the calculation directly without these, but am having trouble
finding the right syntax. \raisebox{0.5\heightof{E}-0.25in} does not work.
The closest question seems to be the one here, but this approach doesn't
align properly. I want the vertical image center to be aligned with the
midpoint between the text baseline and the letter top (in this case "E").
MWE:
\documentclass{article}
\usepackage{calc}
\begin{document}
\newlength{\lenA}
\newlength{\lenB}
\setlength{\lenA}{\heightof{E}}
\setlength{\lenB}{0.25in}
Text \raisebox{0.5\lenA-0.5\lenB}{\rule{0.25in}{0.25in}} Testing
\end{document}

No comments:

Post a Comment