14

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.

lockstep
  • 250,273
Brian M. Hunt
  • 14,277

3 Answers3

14

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

TH.
  • 62,639
  • 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 01 '11 at 00:07
  • This solution seems not exactly correct; the top of the 'd' in "word" lies above the top of the rest of the sentence. – xFioraMstr18 Jun 05 '22 at 09:03
11

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

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

alt text

chl
  • 8,890
7

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

Philipp
  • 17,641