3

Basically I want to create a (dashed) line between two tree edges. I tried cheating a bit and created such line manually between two hidden nodes. The problem is, I don't get them hidden! There's always a bit of space between the connecting edges and no parameter I tried seemed to help (radius, treenodesize,..).

\documentclass{minimal}

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

\newcommand{\terminal}[1]{\TR{\boldsymbol{#1}}}
\newcommand{\nonterminal}[1]{\TR{#1}}
\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{\nonterminal{M_1}}
  {
    \pstree{\Tr[name=m1]{}}
    {
      \terminal{(}
    }
  }
  \pstree[levelsep=1cm]{\nonterminal{S}}
  {
    \emptyword
  }
  \pstree{\nonterminal{M_2}}
  {
    \pstree{\Tr[name=m2]{}}
    {
      \terminal{)}
    }
  }
  \ncline[linestyle=dashed]{m1}{m2}
}

\end{document}
2

set the nodesep to zero:

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

\newcommand{\terminal}[1]{\TR{\boldsymbol{#1}}}
\newcommand{\nonterminal}[1]{\TR{#1}}
\newcommand{\emptyword}{\TR{\epsilon}}
\newenvironment{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{M_1}}
  {
    \pstree{\Tr[name=m1]{}}
    {
      \terminal{(}
    }
  }
  \pstree[levelsep=1cm]{\nonterminal{S}}
  {
    \emptyword
  }
  \pstree[nodesep=0]{\nonterminal{M_2}}
  {
    \pstree{\Tr[name=m2]{}}
    {
      \terminal{)}
    }
  }
\ncline[linestyle=dashed,nodesep=0.1pt]{m1}{m2}
}

\end{document}

enter image description here

or as an alternative use the offset option:

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

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

\begin{document}

\derivationtree{%
  \pstree[skiplevels=1,levelsep=4cm]{\nonterminal{M_1}}
    { \terminal[name=m1]{(} }
  \pstree[levelsep=1cm]{\nonterminal{S}}
    { \emptyword }
  \pstree[skiplevels=1,levelsep=4cm]{\nonterminal{M_2}}
    { \terminal[name=m2]{)} }
  \ncline[linestyle=dashed,nodesep=-1.5mm,offset=-2cm]{m1}{m2}
}

\end{document}
  • Hmm, it works, kinda. But with nodesep=0, all child nodes inherit that and the space for nodes with text is then smaller. As with thislevelsep I thought that there would also be a thisnodesep but apparently not. So, how do I reset it for further nodes to the original value? – letmaik Sep 25 '12 at 14:21
  • see my edit with skipping a level – user2478 Sep 25 '12 at 14:59
  • That's better, I like the offset way, seems more semantic and has less overhead. Although it probably breaks if the lines aren't parallel. – letmaik Sep 25 '12 at 15:45
  • yes, but you can use offsetA and offsetB – user2478 Sep 25 '12 at 16:05

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.