How do I add a caption to a diagram generated with qtree?

I have a diagram that I created with qtree, but would like to add a caption to it. How can this be done?

-
Welcome to TeX.sx! how about putting it in a figure and using \caption? –  cmhughes Mar 8 '13 at 20:04
This seems to always give Figure 1. <my caption>, and places the diagram in the center of the next page, rather than inline with the text. Is there any alternative to this? –  Rich Ashworth Mar 8 '13 at 20:05
Should the desired caption have a particular formatting? I mean do you want to number the diagram and have a label for it as in Diagram 1: tree showing....? –  Gonzalo Medina Mar 8 '13 at 20:08
Please post a minimal working example (MWE) that shows what you want to achieve. –  hpesoj626 Mar 8 '13 at 20:08
@GonzaloMedina - yes, exactly –  Rich Ashworth Mar 8 '13 at 20:10

One option would be to use the newfloat package to define a new floating object, so then you can use the standard \caption command:

\documentclass{article}
\usepackage{qtree}
\usepackage{newfloat}

\DeclareFloatingEnvironment[fileext=lod]{diagram}

\begin{document}

\begin{diagram}
\centering
\Tree [.S This [.VP [.V is ] \qroof{a simple tree}.NP ] ]\par
\caption{the caption for this diagram}
\end{diagram}

\end{document}


The package offers some other customization possibilities and it cooperates with the caption package.

-