views:

172

answers:

3

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} 
+2  A: 

First, read this: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=letterspace . 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.

AVB
+2  A: 

I'm sure that this could be improved upon, and due to different font implementations at different sizes then it isn't going to be exact, but here's a quick-and-dirty way to do it:

\documentclass[10pt]{article}

\usepackage{pgfmath}
\usepackage{anyfontsize}


\newlength{\mywidth}
\newlength{\testwidth}
\setlength{\mywidth}{4in}
\newcommand{\fixedwidth}[1]{%
\settowidth{\testwidth}{#1}%
\pgfmathsetmacro{\x}{round(\mywidth/\testwidth * 10)}%
\pgfmathsetmacro{\y}{round(\mywidth/\testwidth * 15)}%
\bgroup\fontsize{\x pt}{\y pt}\selectfont#1\egroup}

\begin{document}

\fixedwidth{hello world}

\fixedwidth{greetings earthlings}
\end{document}

In practice, it's a little less than the 4in, but the two lines of text do get scaled to the same amount.

Andrew Stacey
Interesting solution Andrew - it seems that in practice, using the round does not get them to line up _exactly_, but instead very close.
Hooked
Yeah, I wasn't sure whether fonts could be non-integer sizes. I guess that they can, so the "round" may be superfluous. Anyway, you got a better answer so it's not important.
Andrew Stacey
+1  A: 

Check out the package textfit. Usage:

\scaletowidth{width}{text}

or

\scaletoheight{height}{text}
Geoff
Your example:http://i56.photobucket.com/albums/g162/nakedwithbootson/temp.png
Geoff
Of the three examples currently posted (Geoff, Stacey, AVB) this one does the worst at aligning the right-side column exactly. While it looks nice for a larger block of text, for the short headlines I'm looking for its a bit to jagged on the right-side. (+1) For introducing me to the package - its seems useful in its own regard!
Hooked