Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
I don't think there is a way to get the exact width of a dirtree, because it's typeset in a box as wide as the current text width by design. Also \centering confuses it, so it's best to typeset it in a minipage. –  egreg Feb 18 '13 at 10:31
    
@egreg Tried typesetting all 3 sub-figures into seperate minipage environments --still no luck with placing them on one horizontal line. –  phiri Feb 18 '13 at 12:02
1  
Don't leave blank lines between the subfigure environments. A width of 3cm seems good for the example. –  egreg Feb 18 '13 at 13:12

1 Answer 1

up vote 5 down vote accepted

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}
share|improve this answer
    
+1 Thank you for this --minipage worked like a charm. I am still struggling with #2 (using subcaption to place dirtree outputs on single line) though. –  phiri Feb 18 '13 at 13:12
    
Sorry, I forgot to upload that part. Added now. –  Andrew Swann Feb 18 '13 at 13:31
    
Great! Thank you for this. –  phiri Feb 18 '13 at 14:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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