1

I want to align two dirtrees to the top and their respective subcaptions to the bottom. What's more, height of the both frameboxes should be equal (see image below). How can I achieve that?

Here is the image presenting my problem: Trees in subfigures

Here is the respective code:

\documentclass{article}
\usepackage{subcaption}
\usepackage{dirtree}

\begin{document}

\begin{figure}
    \centering
    \begin{subfigure}[b]{0.45\textwidth}
        \framebox[\textwidth]{%
            \begin{minipage}{0.9\textwidth}
                \footnotesize
                \dirtree{%
                .1 /.
                .2 \vdots.
                .2 tmp.
                .3 \vdots.
                .3 test.
                .4 file0.
                .4 file1.
                .4 file1\_symlink -> file1.
                .4 dir3\_symlink -> dir3.
                .4 file8\_hardlink.
                .4 dir1.
                .5 fi.
                .5 file2.
                .5 file3.
                .5 subdir1.
                .6 file4.
                .6 file5.
                .5 subdir2.
                .6 file6.
                .6 file7.
                .4 dir2.
                .5 fifo1.
                .5 fifo2.
                .4 dir3.
                .5 file8.
                .5 file9.
                }
                \caption{Tree 1}
                \label{subfig:tree1}
            \end{minipage}
        }
    \end{subfigure}
    \begin{subfigure}[b]{0.45\textwidth}
        \framebox[\textwidth]{%
            \begin{minipage}{0.9\textwidth}
                \footnotesize
                \dirtree{%
                .1 /.
                .2 \vdots.
                .2 tmp.
                .3 \vdots.
                .3 test.
                .4 dir1.
                .5 f3.
                .5 f4.
                .5 subdir1.
                .5 subdir2.
                .6 f5.
                .4 dir2.
                .4 dir3.
                .4 f1.
                .4 f2.
                .4 f2\_symlink -> f2.
                .4 f4\_hardlink.
                .4 fifo1.
                .4 fifo2.
                }
                \caption{Tree 2}
                \label{subfig:tree2}
            \end{minipage}
        }
    \end{subfigure}
    \caption{Comparison}
    \label{fig:trees-comparison}
\end{figure}

\end{document}
2

The package tcolorbox provides a series of command that help with this and it will also simplify your code. The most relevant feature is that it can construct boxes with an upper and lower part, distribute space between them and give a series of boxes the same height.

\NewTotalTColorBox{\mybox}{m +m}{equal height group=#1, size=fbox,
sharp corners, colback=white, width=\textwidth, space to upper,
lower separated=false, fontupper=\footnotesize, nobeforeafter}{#2}

sets up a box command that takes two arguments, the first the name of the series of boxes that should have the same height, the second the content of the box.

The size=fbox, sharp corners, colback=white make this box much like an ordinary \fbox with no fancy colouring of the backgroup.

space to upper ensure that the part of the contents above \tcblower is top aligned and that the remainder is aligned to the bottom.

lower separated=false turns off tcolorbox's standard printing of a dividing line.

fontupper sets the font to use in the upper part, instead of having to write it each time.

Sample output

\documentclass{article}
\usepackage{subcaption}
\usepackage{dirtree}
\usepackage[xparse]{tcolorbox}

\NewTotalTColorBox{\mybox}{m +m}{equal height group=#1, size=fbox,
sharp corners, colback=white, width=\textwidth, space to upper,
lower separated=false, fontupper=\footnotesize, nobeforeafter}{#2}

\begin{document}

\begin{figure}
  \centering
  \begin{subfigure}[b]{0.45\textwidth}
    \mybox{dirs}{%
    \dirtree{%
    .1 /.
    .2 \vdots.
    .2 tmp.
    .3 \vdots.
    .3 test.
    .4 file0.
    .4 file1.
    .4 file1\_symlink -> file1.
    .4 dir3\_symlink -> dir3.
    .4 file8\_hardlink.
    .4 dir1.
    .5 fi.
    .5 file2.
    .5 file3.
    .5 subdir1.
    .6 file4.
    .6 file5.
    .5 subdir2.
    .6 file6.
    .6 file7.
    .4 dir2.
    .5 fifo1.
    .5 fifo2.
    .4 dir3.
    .5 file8.
    .5 file9.
    }
    \tcblower
    \caption{Tree 1}
    \label{subfig:tree1}
    }
  \end{subfigure}
  \begin{subfigure}[b]{0.45\textwidth}
    \mybox{dirs}{%
    \dirtree{%
    .1 /.
    .2 \vdots.
    .2 tmp.
    .3 \vdots.
    .3 test.
    .4 dir1.
    .5 f3.
    .5 f4.
    .5 subdir1.
    .5 subdir2.
    .6 f5.
    .4 dir2.
    .4 dir3.
    .4 f1.
    .4 f2.
    .4 f2\_symlink -> f2.
    .4 f4\_hardlink.
    .4 fifo1.
    .4 fifo2.
    }
    \tcblower
    \caption{Tree 2}
    \label{subfig:tree2}
    }
  \end{subfigure}
  \caption{Comparison}
  \label{fig:trees-comparison}
\end{figure}

\end{document}

Your Answer

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

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