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").



Text \raisebox{0.5\lenA-0.5\lenB}{\rule{0.25in}{0.25in}} Testing


Three methods:

  1. With tabular

  2. With \raisebox and measuring a capital letter

  3. With \raisebox and1ex` (which is David's solution)


T \begin{tabular}{@{}c@{}}\rule{0.25in}{0.25in}\end{tabular} T
\raisebox{.5\fontcharht\font`E-.5\height}{\rule{0.25in}{0.25in}} T
\raisebox{1ex-0.5\height}{\rule{0.25in}{0.25in}} T


enter image description here

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.

  • yes probably worth mentioning that these centre on the math axis, half the height of E and the x-height of the font respectively. – David Carlisle Aug 21 '13 at 21:20
  • Method 2 does exactly what I want. Where would I find documentation on the effect of the tick mark in .5\fontcharht\font`E-.5\height? – TomH57 Aug 21 '13 at 23:34
  • @TomH57 With "backquote-character" you simply specify the number corresponding to the ASCII code of the character. It's documented in the TeXbook and in TeX by Topic. – egreg Aug 22 '13 at 7:33

The following compares several "midpoints":

  1. 1ex (the unit name is derived from the lowercase letter x), see David's answer.

  2. The middle of the letter E (method from the question).

  3. Math axis, center axis of minus, equals, plus and others. This is also the method of egreg's tabular solution.

  4. Ratio of the strut box. LaTeX puts 30 % of \baselineskip below and 70 % above the base line.

The following example file defines macros \midraiseboxA up to \midraiseboxB and compares them:






  E#1{\testI}xe#1{\testI}- Test #1{\testII} Testing %
  #1{\testII} Eg%





The dependency on package calc can be removed if needed:

  • The expression \heightof is calculated using \settoheight and
  • the calculations can be done with e-TeX's \dimexpr.

Example for \midraiseboxC:


It's easier to use the x-height of the font (although you could measure E if you want)

enter image description here


Text \raisebox{1ex-0.5\height}{\rule{0.25in}{0.25in}} Testing


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.