A newenvironment is defined using varwidth and tikz to get a block of width equal to that of the content within it. It works fine, unless itemization is involved. A MWE is given here.


\tikzstyle{example-box} = [fill=yellow, rectangle]

\node [example-box] (box)



With normal sentences, the width is rightly fit

\item With itemize environment,
\item The width is not auto-set
\item Instead spans the entire textwidth



enter image description here Can anybody suggest a way to make the width auto for itemization/enumeration as well? Thanks in advance.

  • 1
    You are dealing with two very different things here: 1) In the case that works as you want, the material can be typeset in an \hbox (or in \mbox, if you prefer, i.e.: in LR-mode). There can't be any automatic line wrapping. 2) List environments such as itemize, on the other hand, can only be used in vertical mode; they always require an \hsize which determines where automatic line wrapping happens. In your case, the itemize environment is inside a \vbox of width \linewidth. With more text, you would see the line wrapping. If you want automatic line wrapping, ... (continued) – frougon Mar 27 '20 at 16:45
  • 1
    you need to specify a width, and this will be the width of your box (though you can make it bigger by adding space, etc.). On the other hand, if you don't need any automatic line wrapping in the list environment, then I think that itemize is the wrong tool. Implementing your list as a tabular containing a single column of type l would allow the automatic width determination that you appear to want. With the array package, you can use the >{...} syntax to automatically insert the “bullets” and the horizontal skip (space) following them. – frougon Mar 27 '20 at 16:54
  • 1
    Did the above comments help solve your problem ? – BambOo May 13 '20 at 12:15
  • @BambOo, No, I thought the only way is to wrap it in a minipage and specify width manually. – Ashok May 14 '20 at 3:15
  • 1
    If you found a solution, please answer your own question so that other users may benefit from your experience – BambOo May 22 '20 at 11:17

Your Answer

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

Browse other questions tagged or ask your own question.