4

As I need to draw lines between edges, I'd like to have y-splits when there are multiple child nodes. At the moment I realized it through a hidden node and nodesep=0. Unfortunately, I don't know of any way to reset nodesep for the direct parent and children of the split node and therefore the spacings are wrong (see screenshot).

screenshot

\documentclass{minimal}

\usepackage{pstricks,auto-pst-pdf}
\usepackage{pst-tree}

\newcommand{\terminal}[2][]{\TR[#1]{\boldsymbol{#2}}}
\newcommand{\nonterminal}[2][]{\TR[#1]{#2}}
\newcommand{\emptyword}{\TR{\epsilon}}
\newcommand{\derivationtree}[1]
{
    \begin{postscript}
        $   \pstree[treemode=R,nodesep=2pt,treesep=0.4cm,levelsep=1.5cm]{\TR{S}}{#1} $
    \end{postscript}    
}

\begin{document}

\derivationtree{
  \pstree[nodesep=0]{\nonterminal{N_1}}
  {
    \pstree{\Tr{}}
    {
        \pstree[nodesep=2pt]{\nonterminal{N_1}}
        {
            \terminal{[}
        }
        \terminal{[}
    }
  }
}

\end{document}

In the pst-tree manual, there is an example where \psedge is redefined as \ncdiag. But I couldn't really figure out how to do it and how to restrict the effects just for one case.

  • and between which nodes should the line be drawn? – user2478 Sep 25 '12 at 16:32
  • that doesn't matter here, it should be exactly as in the screenshot but with right spacing – letmaik Sep 25 '12 at 16:36
1

Usually one redefines \psedge but it works with any other definition.

\documentclass{minimal}
\usepackage{pstricks,auto-pst-pdf}
\usepackage{pst-tree}
\newcommand\terminal[2][]{\TR[#1]{\boldsymbol{#2}}}
\newcommand\nonterminal[2][]{\TR[#1]{#2}}
\newcommand\emptyword{\TR{\epsilon}}

\def\psEdge#1#2{\ncdiagg[armA=1cm,angleA=0,angleB=180]{#1}{#2}}

\newcommand\derivationtree[1]{
    \begin{postscript}
        $   \pstree[treemode=R,nodesep=2pt,treesep=0.4cm,levelsep=1.5cm]{\TR{S}}{#1} $
    \end{postscript}}

\begin{document}

\derivationtree{%
  \pstree[thislevelsep=2.75cm]{\nonterminal{N_1}}{
        \pstree{\nonterminal[edge=\psEdge]{N_1}}{ \terminal{[} }
        \terminal[edge=\psEdge]{[}
  }
}
\end{document}

enter image description here

  • Ah, looks good! Now the only remaining problem is that the split introduces vertical level spacing (see i48.tinypic.com/282g5fm.png) which I didn't have before. It might not be a standard case, but still... (I wouldn't care, but it doesn't fit on my slide anymore :D) – letmaik Sep 25 '12 at 18:06
  • sure that is the default for existing child nodes. Use a fixed value for treesep if you do not like it (or thistreesep) – user2478 Sep 25 '12 at 18:11
  • Hm but don't I already use a fixed treesep? See my definition for \derivationtree – letmaik Sep 25 '12 at 18:19
  • I cannot see it in my example – user2478 Sep 25 '12 at 18:29
  • See pastie.org/4798814 vs pastie.org/4798820 – letmaik Sep 25 '12 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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