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.

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.

share|improve this question
    
and between which nodes should the line be drawn? –  Herbert Sep 25 '12 at 16:32
    
that doesn't matter here, it should be exactly as in the screenshot but with right spacing –  neo Sep 25 '12 at 16:36

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
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) –  neo 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) –  Herbert Sep 25 '12 at 18:11
    
Hm but don't I already use a fixed treesep? See my definition for \derivationtree –  neo Sep 25 '12 at 18:19
    
I cannot see it in my example –  Herbert Sep 25 '12 at 18:29
    
See pastie.org/4798814 vs pastie.org/4798820 –  neo Sep 25 '12 at 18:31

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.