Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

enter image description here

(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!

share|improve this question
add comment

2 Answers 2

up vote 10 down vote accepted

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:

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}
share|improve this answer
    
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
show 1 more comment

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}

enter image description here

share|improve this answer
    
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
1  
@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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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