# [Tex/LaTex] How to fit text in a box of given size

boxesscalingtext manipulation

Say I want to typeset small piece of text as a logo/motto/slogan or whatever. The text is not much longer than "Lorem Ipsum Dolor". I want this to fit tightly in a box of certain size (e.g. 7x2cm). Two questions here, possibly related:

How can I typeset it so that the text fits a box with certain width?
Assume fixed typeface size, and only the inter-word and inter-glyph
distance is allowed to change.


A (possibly) more advanced version of this:

How can I fit the same text in a box with a given width AND height?
Possibly also adjusting spacing and typeface size?


To illustrate:

Original Version:

Modified spacing, Q1.

Modified spacing plus scaling, Q2.

Sizes, font type, etc. are assumed to be arbitrary. I'm curious how can I do this conceptually. Bonus points for a parameterized macro to experiment with.

Also: I know there are many ways to do it without using TeX and friends (e.g. images, vector graphics, and what not), but I am only interested in ways how to typeset it with TeX, or popular macro packages.

#### Best Answer

To duplicate the answer I gave on the LaTeX Community site...

You could try \resizebox from the graphicx package. See its documentation, page 7:

\resizebox{1in}{!}{Some text}


This will give "Some text" which is exactly 1 inch long. The ! for the second argument means to vary the height by whatever it needs to in order to maintain the aspect ratio. If you did {!}{1in} it would be 1 inch tall instead. If you specify both parameters, it'll be stretched disproportionally so that it is exactly a rectangle of that size, and so on.