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}
Best Answer
Three methods:
With
tabular
With
\raisebox
and measuring a capital letterWith
\raisebox and
1ex` (which is David's solution)I'd use the first method, but it depends on the real application. The centering, for the first method, is with respect to the math axis, where fraction lines would be drawn.