[Tex/LaTex] Framebox and subfigure with dirtree package

dirtreesubcaption

I've integrated dirtree package in my manuscript but having issues with the following.

  1. Framebox: I consistently frame all figures in my manuscript using \framebox, however, applying this to dirtree output messes things up. How do I get past this?
  2. Subfigure: I cannot seem to align 3 figures (Figure 2a, 2b & 2c) on the same horizontal line; I am basically trying to replicate this example. What am I doing wrong here?

Minimal Example

\documentclass[a4paper,10pt]{report}

\usepackage{dirtree}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\framebox[\textwidth]{%
\dirtree{%
.1 \textbf{NDLTD}.
.2 \textbf{OCLC}.
.3 \vdots.
.3 x.xml.
.3 \vdots.
}
}
\caption{How do I frame dirtree-generated figures}
\label{fig:minimal-example:frame-dirtree}
\end{figure}


\begin{figure}
\centering
\begin{subfigure}[b]{0.1\textwidth}
\dirtree{%
.1 \textbf{NDLTD}.
.2 \textbf{OCLC}.
.3 \vdots.
.3 x.xml.
.3 \vdots.
}
\caption{dirtree1}
\label{fig:dirtree1}
\end{subfigure}

\begin{subfigure}[b]{0.1\textwidth}
\dirtree{%
.1 \textbf{NDLTD}. 
.2 \textbf{OCLC}. 
.3 \textbf{2010}. 
.4 \vdots. 
.4 x.xml. 
.4 \vdots. 
.3 \vdots. 
}
\caption{dirtree2}
\label{fig:dirtree2}
\end{subfigure}

\begin{subfigure}[b]{0.1\textwidth}
\dirtree{%
.1 \textbf{NDLTD}. 
.2 \textbf{OCLC}. 
.3 \textbf{2010}. 
.4 \textbf{z}. 
.5 \vdots. 
.5 x.xml. 
.5 \vdots. 
.3 \vdots. 
}
\caption{dirtree3}
\label{fig:dirtree3}
\end{subfigure}
\caption{Combined dirtree structures}\label{fig:dirtrees}
\end{figure}

\end{document}

Best Answer

You can use the \framebox command around a minipage environment as follows:

Sample output

\documentclass[a4paper,10pt]{report}

\usepackage{dirtree}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\framebox[\textwidth]{%
\begin{minipage}{0.9\textwidth}
  \dirtree{%
  .1 \textbf{NDLTD}.
  .2 \textbf{OCLC}.
  .3 \vdots.
  .3 x.xml.
  .3
  \vdots.
  }
\end{minipage}
}
\caption{Framing a dirtree-generated figure}
\end{figure}


\end{document}

For your subfigures, the only real problem is that you have left a blank line (causing a paragraph break) between the environments. Removing these and making them sligtly wider gives:

subfigure output

\documentclass[a4paper,10pt]{report}

\usepackage{dirtree}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\begin{subfigure}[b]{0.3\textwidth}
\dirtree{%
.1 \textbf{NDLTD}.
.2 \textbf{OCLC}.
.3 \vdots.
.3 x.xml.
.3 \vdots.
}
\caption{dirtree1}
\label{fig:dirtree1}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\dirtree{%
.1 \textbf{NDLTD}. 
.2 \textbf{OCLC}. 
.3 \textbf{2010}. 
.4 \vdots. 
.4 x.xml. 
.4 \vdots. 
.3 \vdots. 
}
\caption{dirtree2}
\label{fig:dirtree2}
\end{subfigure}
\begin{subfigure}[b]{0.3\textwidth}
\dirtree{%
.1 \textbf{NDLTD}. 
.2 \textbf{OCLC}. 
.3 \textbf{2010}. 
.4 \textbf{z}. 
.5 \vdots. 
.5 x.xml. 
.5 \vdots. 
.3 \vdots. 
}
\caption{dirtree3}
\label{fig:dirtree3}
\end{subfigure}
\caption{Combined dirtree structures}\label{fig:dirtrees}
\end{figure}

\end{document}