[Tex/LaTex] Resize box to fit text


I would like to have a box which changes width depending on the text in it. Shorter sentences should have a narrow box, and as the sentence gets longer the box should grow (until it is as wide as the text, then I would like a line break). Font size should not be affected. The best solution I've got so far (see below) scales the text when it is short.

  \resizebox{\textwidth}{!}{Some variable-length text}

Best Answer

You can put a frame around text with the \fbox command:


To put text in an ellipse, you can use the TikZ/PGF package and its shapes.geometric library:





% You can also make a \newcommand for this
\tikz[baseline=(e.base)] \node[ellipse,draw] (e) {text};


enter image description here

Note that in both cases the text acts as one "big" box relative to the paragraph and will not be broken in separate lines.

If you wish to typeset whole paragraphs in a frame that does not expand to full line width if the paragraph fits on one line, then the following approach (inspired by \@makecaption) might do:



    \fbox{\parbox{\@tempdima}{\strut #1}}%
    \fbox{\strut #1}%




\noindent\varbox{not too much text}


Typesetting large blocks inside ellipses does not seem practical to me.