11

In XeTeX, if I have a line with two font sizes, how can I arrange to have the smaller font aligned to either the center or top of the line?

e.g.

\newfontinstance\biggoth[Color=000000,Scale=5.0]{Cloister Black}
\newfontinstance\smallgoth[Color=000000,Scale=2.0]{Cloister Black}


\biggoth Hello \smallgoth World

The "Hello" aligns to the bottom of the line.

I'm grateful for any thoughts and input.

11

In general, TeX keeps the baselines of all characters (and boxes) at the same height. For a single word, you can do what chl suggested and raise the text using \raisebox. Rather than guessing at how much to raise it, you can put the word in a box (perhaps with a strut), measure its height, and then raise it appropriately.

\documentclass{article}
\newcommand*\raiseup[1]{%
        \begingroup
        \setbox0\hbox{\tiny\strut #1}%
        \leavevmode
        \raise\dimexpr \ht\strutbox - \ht0\box0
        \endgroup
}
\begin{document}
Here's some text. Here's a raised \raiseup{word}.
\end{document}

alt text

  • 2
    You may want to crop your image. – Hendrik Vogt Dec 31 '10 at 16:04
  • @Hendrik: Yeah, I just used Troy Henderson's LaTeX Previewer to generate it before going to bed. – TH. Dec 31 '10 at 21:19
  • @TH (+1) Great! I wondered how easy it should be to get box height. Here it is... – chl Dec 31 '10 at 22:57
  • @chl: TeX has \ht for height, \dp for depth, and \wd for width. Width is obvious. Height is the height above the baseline, depth is the distance below the baseline. All are (normally) nonnegative numbers. You can also set any of them: \wd0=3in for example, sets the width of box 0 to 3 inches. – TH. Jan 1 '11 at 0:07
9

Maybe you can just play with \raisebox, e.g.

\biggoth Hello \raisebox{.5ex}{\smallgoth World}

alt text

4

Here is another possibility, very similar to TH.'s suggestion:

\documentclass{minimal}
\usepackage{fontspec}
\newfontinstance\biggoth[Color=000000,Scale=5.0]{Cloister Black}
\newfontinstance\smallgoth[Color=000000,Scale=2.0]{Cloister Black}
\newsavebox{\mybox}
\newcommand*{\tlap}[1]{%
  \sbox{\mybox}{#1}%
  \raisebox{-\ht\mybox}{\usebox{\mybox}}%
}
\newcommand*{\mlap}[1]{%
  \sbox{\mybox}{#1}%
  \raisebox{-0.5\ht\mybox}{\usebox{\mybox}}%
}
\begin{document}
\tlap{\biggoth Hello}
\tlap{\smallgoth World}

\mlap{\biggoth Hello}
\mlap{\smallgoth World}
\end{document}

alt text

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.