# Make the enlarged digit vertically centered in normal text (digits almostly) height.

I want a digit inside around other digits could centered vertically in height, without affecting by normal font size setting, as image show:

(The enlarged six is {\Large6}) but I couldn't get the result by using the \raisebox command and the ex length unit to raise. Please help!

-

Using \raisebox is the right way. You can use \height to refer to the height of the content i.e. the height above the baseline. The \depth should be zero for normal numbers. You then need to subtract the \height from the normal height and divide it by 2. The normal height from an uppercase letter is about 1.6ex or 80% of the \strut height given by \ht\strutbox. You can use e-TeX's \dimexpr to do the calculation.

\documentclass{article}

\newcommand{\vcentered}{\raisebox{.5\dimexpr.8\ht\strutbox-\height\relax}}

\begin{document}

0000\vcentered{\Large 6}00000\vcentered{\small 9}00000

0000\vcentered{\Huge 6}00000\vcentered{\tiny 9}00000

\end{document}


### Result:

You could do it even more accurate if you would provide a reference for the normal height. In addition you could also take the depths in account.

\documentclass{article}

\newsavebox{\vrefbox}
\newcommand{\setvref}{\sbox{\vrefbox}}
\newcommand{\vcentered}{\raisebox{.5\dimexpr\ht\vrefbox-\height\relax}}

\begin{document}

\setvref{0}0000\vcentered{\Large 6}00000\vcentered{\small 9}00000

\huge
\setvref{0}0000\vcentered{\Huge 6}00000\vcentered{\tiny 9}00000

\end{document}

-
tikz is redundancy? –  Leo Liu Apr 21 '11 at 15:04
@Leo: tikz would be overkill. –  Martin Scharrer Apr 21 '11 at 15:05
@Martin So why is it in the preamble? :-) (Which was Leo's question.) –  Alan Munn Apr 21 '11 at 16:58
@Alan: Ups. It's in my default preamble and I forgot to delete it in one of the code examples. Sorry, I didn't really understood what Leo meant. –  Martin Scharrer Apr 21 '11 at 17:36
@M.S. That is exactly what I want! Thanks! –  Stufazi Hoqckt Apr 22 '11 at 13:24

I would use:

\newcommand\vcentered[1]{\ensuremath{\vcenter{\hbox{#1}}}}


instead of Martin's definition. Although it gets a little different centered text, it is originally designed for vertical alignment in TeX.

The key is usage:

\vcentered{00000}\vcentered{\Huge6}\vcentered{00000}%
\vcentered{\tiny 9}\vcentered{00000}


-
This gives my i.imgur.com/zfNA2.png. Especially the smaller 9 isn't correctly centered. AFAIK \vcenter centers to the baseline. The OP needs to have it centered towards the middle of the surrounding 0s. –  Martin Scharrer Apr 21 '11 at 15:08
@Martin: See the usage. –  Leo Liu Apr 21 '11 at 15:10
@Martin: \vcenter centers with respect to the axis of formulas; it's the imaginary line where the fraction lines are set. –  egreg Apr 21 '11 at 15:43
Thanks all above –  Stufazi Hoqckt Apr 22 '11 at 13:23