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 need a box that fulfils these conditions:

  1. It can contain multiple lines (and paragraphs) of text (unlike \hbox)
  2. A line that is longer then \textwidth is split to the next line (like \parbox, \vbox and unlike \hbox, \mbox)
  3. The content of the box is surrounded closely. That is width of the box is automatically set to width of content (like \hbox, unlike \vbox and \parbox). Because of 3. width of box should actually be minimum of \textwidth and width of box content. Height is height of box content.

How can I get such a behaviour?

share|improve this question
add comment

1 Answer

varwidth needs only a length which will be the maximum of the allowed box width

\documentclass[a5paper]{article}
\usepackage{varwidth}    
\begin{document}

\fbox{%
\begin{varwidth}{\textwidth}
some text
\end{varwidth}}

\fbox{%
\begin{varwidth}{\textwidth}
some more text to see if there can be a line break at the end
of the line with this nonsense text
\end{varwidth}}

\fbox{%
\begin{varwidth}{0.5\textwidth}
some text
\end{varwidth}}

\fbox{%
\begin{varwidth}{0.5\textwidth}
some more text to see if there can be a line break at the end
of the line with this nonsense text
\end{varwidth}}

\end{document} 

enter image description here

share|improve this answer
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.