[Tex/LaTex] dynamic font size for hbox

fontsfontsizexetex

I would like to create an element in TeX, that is defined as a horizontal box with fixed width and to have few lines (three in my case). Each line should align by its size to the hbox size automatically – I do not want to do it by font size, because then it wouldn't be precisely the same length.

Needless to say, the lines are different in character count.

Same
Word length
Even though lines are different

In this case the first line should be of really large font, the second slightly smaller and the third one the smallest.

I would like to use XeTeX with its ligation capability to spice up the font a bit.

Thank you very much for your help (in advance)

Best Answer

Here’s a LaTeX version of what Aditya did:

\documentclass[12pt]{article}
\usepackage{calc,fontspec,graphicx}
\setmainfont[Ligatures=Rare]{Didot LT Pro}
\begin{document}
\centering
% scale to 3 inches
\resizebox{3in}{!}{Same}\\[.75em]% adjust vertical spacing to taste
\resizebox{3in}{!}{Word length}\\[.5em]
\resizebox{3in}{!}{Even though lines are different}\\

\vspace{5ex}

% scale to length of second line
\Huge
\resizebox{\widthof{Word length}}{!}{Same}\\
Word length\\[-.25em]
\resizebox{\widthof{Word length}}{!}{Even though lines are different}
\end{document}

Didot scaled in two ways

I’m not competent to automate this, and I doubt one should try: for best results, one needs to adjust both vertical spacing and width manually, taking into account the shapes of the glyphs and the effect desired. E.g., to my eye, the width of first line looks more like the others if I scale it to 3.12 inches. And there may be need to add or substract some \hspace at the beginning of one or another line, because what’s exactly centered may look off-center to the eye, again depending on the shapes of the glyphs.

This approach takes time, but if a piece of text is worth setting in this style, it’s worth the effort to make manual adjustments.