Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
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 '11 at 7:44
add comment

1 Answer

up vote 5 down vote accepted

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

\documentclass{article}
\usepackage[landscape]{geometry}% http://ctan.org/pkg/geometry
\usepackage{varwidth}% http://ctan.org/pkg/varwidth
\begin{document}
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}}
\end{document}

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.

share|improve this answer
    
thanks for the hint "varwidth" . –  nicolas roy Dec 21 '11 at 8:36
    
@nicolasroy: Yes, you need to know what to search for in order to find things - slightly catch-22-ish. :) –  Werner Dec 22 '11 at 19:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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