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 am a TeX newbie, trying to make a syntax tree. What I'm going for is this:

        X
       / \
      X   \
     / \   \
    X   \   \
   / \   \   \
  X   \   \   \
 / \   \   \   \
A   B   C   D   E
a   b   c   d   e

where the bottom row includes some subscripts. My code is as follows:

\pstree[levelsep=5ex]{ \TR{X} }{
  \pstree{ \TR{X} }{
    \pstree{ \TR{X} }{
      \pstree{ \TR{X} }{
        \TR{\shortstack{{\em A}\\a}}
        \TR{\shortstack{{\em B}\\b}}
      }
      \TR{\shortstack{{\em C}\\c}}
    }
    \TR{\shortstack{{\em D}\\d}}
  }
  \TR{\shortstack{{\em E}\\e}}
}

Two questions:

a) How can I align the leaf nodes at the bottom instead of immediately beneath their mother node?

b) The vertical spacing of the things in the shortstack is inconsistent (probably by some sort of "if it fits" criterion - if if there's an "j" or a "g" on the upper word, the spacing increases to accomodate the downstroke). Is there a better way of writing things one beneath another that will always have the same vertical spacing?

EDIT: as requested, minimal example of node-internal formatting problem:

\pstree[levelsep=5ex]{ \TR{Compare:} }{
  \TR{\shortstack{h\\j}}
  \TR{\shortstack{m\\n}}
}

Notice how higher "h" is compared to "m" ("j" and "n" being level).

share|improve this question
    
See if this question helps you: How to draw syntactical trees with parallel leafs for a natural language?. Unless you must use pstricks for independent reasons, I recommend using tikz-qtree for this. –  Alan Munn Oct 24 '11 at 16:56
    
Dunno, I couldn't get in-node formatting to work in tikz-qtree. Besides, this is almost good-enough (if it only weren't for the damn shortstack spacing problems) –  Amadan Oct 24 '11 at 19:09
    
I guess the question is how you want the tree to look. As you have more nodes and if the tree has right hand nodes that themselves branch, having the branches project directly to the terminals makes for a very large tree. If the example in my answer to the linked question is a satisfactory way to represent the terminal nodes, edit your question to show a minimal example of the problem you are having with the in-node formatting, and maybe we can solve that. –  Alan Munn Oct 24 '11 at 19:23
    
@AlanMunn: Edited –  Amadan Oct 24 '11 at 19:32
    
@Amadan: See my answer to correct for this vertical misalignment. –  Werner Oct 24 '11 at 19:42

3 Answers 3

up vote 3 down vote accepted

Using \skiplevel{...} or \skiplevels{<num>}...\endskiplevels you can push nodes down a (or <num>) level(s) to line them up with nodes on a lower level. The projection is such that it keeps the horizontal alignment as if the nodes were on their original level.

Additionally, instead of using \substack, you could add the contents in a tabular like in the macro \stackit{<top>}{<bottom>} below. It places <top> and <bottom> in a tabular (aligned at the top [t]) with center alignment (and no inter-column spacing @{} on either side). Additionally, <top> is typeset using emphasize {\em ..}. All the baselines will be vertically aligned. If you have a more complex arrangement of leave node labels, then other alternatives also exist:

enter image description here

\documentclass{article}
\usepackage{pst-tree}% http://ctan.org/pkg/pst-tree
% A macro to stack leave node contents: \stackit{<top>}{<bottom>}
\newcommand{\stackit}[2]{\begin{tabular}[t]{@{}c@{}}{\em #1}\\#2\end{tabular}}
\begin{document}
\pstree[levelsep=5ex,nodesep=3pt]{ \TR{X} }{
  \pstree{ \TR{X} }{
    \pstree{ \TR{X} }{
      \pstree{ \TR{X} }{
        \TR{\stackit{A}{a}}
        \TR{\stackit{B}{b}}
      }
      \skiplevel{\TR{\stackit{C}{c}}}
    }
    \skiplevels{2}\TR{\stackit{D}{d}}\endskiplevels
  }
  \skiplevels{3}\TR{\stackit{E}{e}}\endskiplevels
}
\end{document}​
share|improve this answer
    
Oooh, tabular works great! Although renewcommand fails with LaTeX Error: \stackit undefined.... Works with newcommand though. Weird. Anyway - thank you! –  Amadan Oct 24 '11 at 19:42
    
Sorry, corrected the code now - \renewcommand is only used if the macro already exists. If not, use \newcommand. \providecommand would also have worked, which executes either \renew... or \new... based on the existence of the command. –  Werner Oct 24 '11 at 19:45

Do you mean something like skiplevel?

\documentclass{article}
\usepackage{pst-tree}
\begin{document}

\pstree[treesep=1.2cm,levelsep=0.5cm]{ \TR{X} }{
  \pstree{ \TR{X} }{
    \pstree{ \TR{X} }{
      \pstree{ \TR{X} }{
        \TR{\shortstack{{\em A}\\a}}
        \TR{\shortstack{{\em B}\\b}}
      }
      \skiplevels{1}%\skiplevel{\Tn\Tn}
        \TR{\shortstack{{\em C}\\c}}
      \endskiplevels
      }
      \skiplevels{2}%\skiplevel{\Tn\Tn}
            \TR{\shortstack{{\em D}\\d}}
      \endskiplevels
    }
    \skiplevels{3}%\skiplevel{\Tn\Tn}
        \TR{\shortstack{{\em E}\\e}}
    \endskiplevels
  }
\end{document}
share|improve this answer
\documentclass{article}
\usepackage{pst-tree}
\newcommand\Stack[2][0.8]{{\def\arraystretch{#1}\tabular{@{}c@{}}#2\endtabular}}
\begin{document}

\pstree[levelsep=10mm,nodesep=1mm]{ \TR{X} }{
  \pstree[]{ \TR{X} }{
    \pstree{ \TR{X} }{
      \pstree[treesep=5mm]{ \TR{X} }{
        \TR{\Stack{\em A\\a}}
        \Tn
        \TR{\Stack{\em B\\b}}
        \Tn
      }
      \skiplevel{\TR{\Stack{\em C\\c}}}
    }
    \skiplevels{2}\TR{\Stack{\em D\\d}}\endskiplevels
  }
  \skiplevels{3}\TR{\Stack{\em E\\e}}\endskiplevels
}
\end{document}

enter image description here

share|improve this answer

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.