I want to have a box, aligned based on top border. I can do this with minipage[t], but i would have to specify the width, which i do not want. What is thus the simplest way to have a top-aligned box, with dynamic width?

  • 2
    The varwidth package provides varwidth which is exactly like minipage, but shrinks to the natural width of it's contents. Is this what you're after? If not, please provide more detail - perhaps in the form of an image.
    – Werner
    Dec 21, 2011 at 7:44

1 Answer 1


Here is a short example showing the difference between varwidth (from the varwidth package) and other fixed-width boxes like \parbox and minipage:

enter image description here

\usepackage[landscape]{geometry}% http://ctan.org/pkg/geometry
\usepackage{varwidth}% http://ctan.org/pkg/varwidth
Some text \fbox{\parbox[t]{0.25\textwidth}{in here \rule{5em}{1pt} \par and here}}\ 
Some text \fbox{\begin{minipage}[t]{0.25\textwidth}in here \rule{5em}{1pt} \par and here\end{minipage}}    Some text \fbox{\begin{varwidth}[t]{0.25\textwidth}in here \rule{5em}{1pt} \par and here\end{varwidth}}

Note how the width for each box is specified as 0.25\textwidth. However, only the last shrunk down to the natural width of the contents.

Shrinking is a natural process in terms of boxing. Enlarging in a similar context as above is less natural, since one would not know where to start breaking lines.

  • @nicolasroy: Yes, you need to know what to search for in order to find things - slightly catch-22-ish. :)
    – Werner
    Dec 22, 2011 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.