TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{qtree}

\declaretheorem[name=Example,qed=\ensuremath{\triangleleft}]{example}
\declaretheorem[name=Example2]{example2}

\begin{document}

\begin{example}
    Bla:

    \Tree [.cons [.s [.s [.s 0 ] ] ] [.cons [.s 0 ] nil ] ]
\end{example}

\begin{example2}
    Bla:

    \Tree [.cons [.s [.s [.s 0 ] ] ] [.cons [.s 0 ] nil ] ]
\end{example2}

\end{document}

The second one is centered, the first isn't. Why and what to do?

In the end I'd like to align several trees horizontally like that:

\begin{example2}
    Bla:

    \Tree [.nil ]
    \Tree [.cons 0 nil ]
    \Tree [.cons [.s [.s [.s 0 ] ] ] [.cons [.s 0 ] nil ] ]
\end{example2}
share|improve this question

From the documentation of qtree:

Qtree attempts to align the topmost label of the tree with the baseline of the text, similarly to the effect of the [t] option for \parbox alignment. To center trees vertically on the baseline, enclose the entire tree in a tabular environment.

You have two strategies:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{qtree}

\declaretheorem[name=Example,qed=\ensuremath{\triangleleft}]{example}

\begin{document}

\begin{example}
Bla:

\raisebox{\depth}{%
  \Tree [.cons [.s [.s [.s 0 ] ] ] [.cons [.s 0 ] nil ] ]%
}
\end{example}

\end{document}

The second strategy consists in using tikz-qtree that shares the same syntax with qtree, but is much more powerful:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{tikz-qtree}

\declaretheorem[name=Example,qed=\ensuremath{\triangleleft}]{example}

\begin{document}

\begin{example}
Bla:

\begin{tikzpicture}
  \Tree [.cons [.s [.s [.s 0 ] ] ] [.cons [.s 0 ] nil ] ]
\end{tikzpicture}
\end{example}

\end{document}

The placement is not really perfect in both cases, so some small adjustment may be necessary.

For centering, use an equation* environment and the \qedhere feature:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{tikz-qtree}

\declaretheorem[name=Example,qed=\ensuremath{\triangleleft}]{example}

\begin{document}

\begin{example}
Bla:

\begin{equation*}
\begin{tikzpicture}
  \Tree [.cons [.s [.s [.s 0 ] ] ] [.cons [.s 0 ] nil ] ]
\end{tikzpicture}}\qedhere
\end{equation*}
\end{example}

\end{document}

enter image description here

share|improve this answer
    
I see no difference for both strategies. The tree is still aligned at the left and not centered like when not using a qed symbol. – letmaik Feb 27 '13 at 21:30
    
@neo I've added how to center the tree – egreg Feb 27 '13 at 21:38
    
Do you also know why the tree isn't centered? – letmaik Feb 28 '13 at 19:29
    
Regarding the centering, unfortunately using an equation breaks when there are many trees which would otherwise just break to a new line. For the moment, I just work around it by using my original code and adding a white line at the end. The qed symbol then is a bit below the lowest tree leaf... – letmaik Mar 1 '13 at 12:14
    
@neo I wouldn't rely on automatic line breaking in this case. – egreg Mar 1 '13 at 12:21

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.