3

I just need nested boxes in latex. Like this:

enter image description here

with the following constraints:

  • the outermost box (black) will never be larger than \textwidth or pagewidth
  • there is never more than one box in a row

I've already tried all kinds of fboxes, makeboxes, colorboxes, stacks etc. This comes close, but it still has the problem with several boxes in a row.

Here is a MWE:

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\begin{document}
  {\fboxrule=.75pt%
   \fbox{\stackunder{Box 1 }
   {
    \fbox{\stackunder{ Box 2 }{
        \fbox{\stackunder{ Box 4 }{}}  
    }}      
    \fbox{\stackunder{ Box 3 }{}}
   }
  }
 }
\end{document}

enter image description here

How can I get box 3 under box 2 and limit the entire width to the pagesize?

2
  • 1
    please add a MWE for your problem.
    – naphaneal
    Feb 15, 2018 at 14:56
  • I've updated the question. Feb 15, 2018 at 15:41

1 Answer 1

3

I just added another \stackunder with the box2/4 as the first argument, and the box3 as the 2nd.

I also left-aligned the stacks (by default).

However, note that an \fbox approach will not limit the eventual overall width, unless you make the content of the \fbox to be, for example, a \parbox of specified width.

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\def\stackalignment{l}
\begin{document}
  {\fboxrule=.75pt%
   \fbox{\stackunder{Box 1 }
   {
    \stackunder{%
    \fbox{\stackunder{ Box 2 }{
        \fbox{\stackunder{ Box 4 }{}}  
    }}  
    }{%   
    \fbox{\stackunder{ Box 3 }{}}%
    }
   }
  }
 }
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .