[Tex/LaTex] How to scale a dirtree inside a figure

boxesdirtreefloatsscaling

I drew a tree structure with \dirtree. This tree is located in a {figure} environment. It is possible to adjust the size of the figure?

With \includegraphics one can do it with scale. Is there a similar attribute for figure?

My code looks like this (MWE):

\documentclass{article}
\usepackage{dirtree}
\begin{document}

\begin{figure}[H]
\label{fig:directory}       
\fbox{%
  \parbox{\textwidth}{%
        \begin{center}
            \begin{minipage}[t]{0.3\linewidth}
                CSS3
                \dirtree{%
                .1 html.
                    .2 head.
                        .3 title.
                        .3 meta.
                        .3 style.
                    .2 body.
                        .3 div (square).
                            .4 div (card).
                }
            \end{minipage}
            %
            \begin{minipage}[t]{0.3\linewidth}
                SVG
                \dirtree{%
                .1 html.
                    .2 head.
                        .3 title.
                        .3 meta.
                        .3 style.
                    .2 body.
                        .3 svg.
                            .4 image.
                                .5 animateTransform.
                }
            \end{minipage}  
            %
            \begin{minipage}[t]{0.3\linewidth}
                Canvas
                \dirtree{%
                .1 html.
                    .2 head.
                        .3 title.
                        .3 meta.
                    .2 body.
                        .3 canvas.
                        .4 script.
                }
            \end{minipage}
        \end{center}
  }%
}
\end{figure}

\end{document}

Screenshot:

enter image description here

Best Answer

dirtree is just text, so you could use \scalebox and friends but it's usually better with text just to select a smaller fontsize as that gives more regular output. so \footnotesize or \small or whatever.

enter image description here

I used \small here, I also fixed several other spacing issues (you need to allow space for the fbox rules and padding when allocating the width to the outer \parbox Also you need to beware of word spaces between the minipages. Rather than shrink too much, I allowed the central tree box to overlap the right hand one as the actual trees don't overlap, and I added float package so that H means "Here`rather than an unreported syntax error that makes the float go the end of the document.

\documentclass{article}
\usepackage{dirtree,float}
\begin{document}

\noindent X\dotfill X

\begin{figure}[H]
\label{fig:directory}       
\fbox{%
  \parbox{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}{%
            \centering\small
            \begin{minipage}[t]{0.3\linewidth}
                CSS3
                \dirtree{%
                .1 html.
                    .2 head.
                        .3 title.
                        .3 meta.
                        .3 style.
                    .2 body.
                        .3 div (square).
                            .4 div (card).
                }
            \end{minipage}\hfill
            %
            \begin{minipage}[t]{\dimexpr0.3\linewidth+50pt\relax}
                SVG
                \dirtree{%
                .1 html.
                    .2 head.
                        .3 title.
                        .3 meta.
                        .3 style.
                    .2 body.
                        .3 svg.
                            .4 image.
                                .5 animateTransform.
                }
            \end{minipage}\hspace{-50pt}\hfill 
            %
            \begin{minipage}[t]{0.3\linewidth}
                Canvas
                \dirtree{%
                .1 html.
                    .2 head.
                        .3 title.
                        .3 meta.
                    .2 body.
                        .3 canvas.
                        .4 script.
                }
            \end{minipage}

  }%
}
\end{figure}

\end{document}