# Natural deduction (or similar) as TikZ tree

I'm wondering if it's possible to make TikZ trees render in a way similar to natural deduction (proof) trees. Specifically I would like a tree which, rather than edges from parent to child, has lines horizontally (assuming the tree grows up or down) over each subtree.

I'm still new to TikZ and my best solution so far is to draw the tree without edges and use the fit library to construct bounding boxes for all the subtrees and then use the anchors of the bounding boxes to draw lines, hardly a satisfactory solution.

(I suspect I could be using chains, but as far as I can see you'd lose the convenient notation for trees.)

EDIT: If it was conveniently possible to traverse the tree nodes in a \foreach fashion the tedious part could at least be automated, would something like this be possible?

EDIT: I guess one could tweak the level distance so as to make the edged horizontal, this feels like rather a hack though.

EDIT: Here's an example of what I'm after

produced with

\begin{tikzpicture}[grow'=up,level distance=4ex,
edge from parent/.code={},
level/.style={sibling distance=10em/#1}]
\node (A) {A}
child { node (B) {B}
child { node (D) {D} }
child { node (E) {E} } }
child { node (C) {C}
child { node (F) {F} }
child { node (G) {G}
child { node (H) {H} }
child { node (I) {I} }
child { node (J) {J} } } } ;
\node (SubA) [fit=(B) (C)] {};
\node (SubB) [fit=(D) (E)] {};
\node (SubC) [fit=(F) (G)] {};
\node (SubG) [fit=(H) (I) (J)] {};
\foreach \root in {SubA, SubB, SubC, SubG}{
\draw [thick] (\root.south west) -- (\root.south east);
};
\end{tikzpicture}
-
Could you point to an example of the kinds of results you'd like to achieve? –  Jake Oct 23 '11 at 23:18
Check out some of the items here: LaTeX for Logicians. For trees generally of this sort, I recommend tikz-qtree. There are a number of examples here on the site that might be of use: qtree (make sure you choose the "newest" view of the tag's questions). –  Alan Munn Oct 23 '11 at 23:26
@Alan Minn: Thanks for the suggestion, but I already use tikz-qtree. The problem isn't with structuring the trees but with how they are drawn. Also I know there are packages around for drawing natural-deduction style trees, but I'm specifically interested in drawing them with tikz, and, even more specifically, using tikz's tree facility. –  Tilo Wiklund Oct 23 '11 at 23:49
@Jake: Done, hope that clarified things. –  Tilo Wiklund Oct 24 '11 at 0:03

You can specify the edge from parent path to yield horizontal lines. Below is a style that is adapted from the predefined style edge from parent fork up from the trees library:

\documentclass[oneside]{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
edge from parent path={
(\tikzparentnode\tikzparentanchor)
+(0pt,.5\tikzleveldistance)
-- (0pt,-.5\tikzleveldistance -| \tikzchildnode\tikzchildanchor)
-- +(0.25cm,0pt)
-- +(-0.25cm,0pt)
},
grow'=up,level distance=4ex,
level/.style={sibling distance=10em/#1}]
\node (A) {A}
child { node (B) {B}
child { node (D) {D} }
child { node (E) {E} } }
child { node (C) {C}
child { node (F) {F} }
child { node (G) {G}
child { node (H) {H} }
child { node (I) {I} }
child { node (J) {J} } } } ;

\end{tikzpicture}

\end{document}
-
Very nice! Somehow I'd managed to miss the trees library. –  Tilo Wiklund Oct 24 '11 at 0:15
No problem. Note that you don't need to load the trees library with this example, I just used one of its styles as a starting point. –  Jake Oct 24 '11 at 0:16