latextypesetting

Variable font height via tables in LaTeX


I've been looking for a more elegant solution to the following typesetting problem. Consider those banners found in print media where the text is aligned like:

B    I    G        T   E   X   T
small text small text small text
m o r e    m e d i u m   t e x t

The font sizes are adjusted so that the height is scaled down for longer lines of text such that each line has equal width. I've written a small script that runs each line separately, compiles, crops the resulting pdf and then \includegraphics each in a table. This gives the desired effect but requires an both an outside script and pdfcrop (which only crops to a white bounding box). Since much of LaTeX is self-aware, I imagine it would be possible to have it recognize the width of a box and scale it appropriately so that any text fits exactly into the desired width.

Any thoughts or ideas on how a pure LaTeX implementation might work?

EDIT As a supplement to the suggested solution by AVB (since large code in comments looks awful), I've posted below the code used so that others may find it easily.

\documentclass[]{article}
\usepackage[pdftex]{graphicx}
\begin{document}
\begin{table}[l]
\resizebox{10cm}{!}{BIG Text} \\
\resizebox{10cm}{!}{small text small text small text} \\ 
\resizebox{10cm}{!}{Medium Text Medium Text}
\end{table} \end{document} 

Solution

  • First, read the TeX FAQ entry titled Changing the space between letters. Depending on your circumstances, the packages and recommendation in that FAQ may suffice.

    Also, take a look at the \scalebox and \resizebox commands in the graphicx package. They do what the names imply.