[pstricks] pst-tree label position

Jean-Come Charpentier Jean-Come.Charpentier at wanadoo.fr
Fri Oct 1 01:35:11 CEST 2004


Jonne Zutt wrote:

>Dear pstrickers,
>
>I am using pst-tree to draw a binary tree diagram.
>Can someone help me positioning a label correctly?
>
>Each node has several formulas that I put in a tabular to align
>formula number, formule and the rule that was applied.
>There are always 0 or 2 children. If there are two, I would like
>to label this branch in the center, like this:
>
>       formula_1
>       formula_2
>           /\
>          /  \
>         /(10)\
>        /      \
>       /        \
>      /          \
>     /            \
>   formula_3    formula_4
>   etc.         etc.
>
>I provided a (auto-generated) latex example below (I am not happy with
>the placement of the (##) labels).
>
>ps > reason why I set the huge page size is that I want to convert the
>tree to an image file. Hence, I do not want to have multiple pages.
>Another problem I have is to clip the extra whitespace out of the image
>(but this might not be the correct place to ask for help on that =)
>  
>

Yes!  100in, it's ... well ... somewhat too big, no ?
To avoid multiple page, it's simpler to typeset with a small font.  In 
fact don'y use anything, with a correct code, it works fine.  I suppose 
that there was the \pstree instead of \Mynode directly for terminal nodes.

>ps2 > i'm afraid my mailer will break some lines :(
>  
>

I don't think.

Here my solution.  A classical tree with \rput for the label (your label 
depend of the node, not of the line) and no \pstree for terminal node. 
No more \thput, nor optional argument for \Mynode

\documentclass{article}
\usepackage[dvips]{color}
\usepackage{pst-tree}
\usepackage{geometry}
\geometry{a4paper, left=1in, right)1in, top=1in, bottom=1in, noheadfoot}

\pagestyle{empty}
% Three colors:
% Blue  = regular formulas
% Black = literals ( [~]p_0 )
% Red   = literal that closes tree

\newcommand{\of}{$\vee$}
\newcommand{\en}{$\wedge$}
\newcommand{\imp}{$\rightarrow$}
\newcommand{\desda}{$\leftrightarrow$}
\newcommand{\niet}{$\neg$}

\newbox\Nodebox
\newcommand{\MyNode}[3]{%
  \TR{%
    \setbox\Nodebox=\hbox{%
      \psframebox{\begin{tabular}[b]{#1}#2\end{tabular}}%
    }%
    \rput(0.5\wd\Nodebox,-1){#3}%
    \relax
    \copy\Nodebox
  }%
}

\psset{levelsep=*4cm} % to tune

\begin{document}
\pstree{\MyNode{rll}{%
    1. & \textcolor{black}{a\imp{}b\of{}c\imp{}d\en{}e} &
        (hypothese)\\
    2. & \textcolor{black}{e\of{}f\imp{}g} & (hypothese)\\
    3. & \textcolor{black}{\niet{}(a\imp{}c\imp{}g)} &
        (\niet{} conclusie)\\
    4. & \textcolor{black}{a\en{}\niet{}(c\imp{}g)} &
        (\imp{}-regel, 3)\\
    5. & \textcolor{blue}{a} & (\en{}-regel, 4)\\
    6. & \textcolor{black}{\niet{}(c\imp{}g)} &
        (\en{}-regel, 4)\\
    7. & \textcolor{black}{c\en{}\niet{}g} &
        (\imp{}-regel, 6)\\
    8. & \textcolor{blue}{c} & (\en{}-regel, 7)\\
    9. & \textcolor{blue}{\niet{}g} & (\en{}-regel, 7)\\
    10. & \textcolor{black}{\niet{}(e\of{}f)\of{}g} &
        (\imp{}-regel, 2)\\
    11. & \textcolor{black}{\niet{}a\of{}(b\of{}c\imp{}d\en{}e)} &
        (\imp{}-regel, 1)}{10}}{
  \pstree{\MyNode{rll}{%
      12. & \textcolor{black}{\niet{}(e\of{}f)} & \\
      13. & \textcolor{black}{\niet{}e\en{}\niet{}f} &
          (\of{}-regel, 12)\\
      14. & \textcolor{blue}{\niet{}e} &
          (\en{}-regel, 13)\\
      15. & \textcolor{blue}{\niet{}f} &
          (\en{}-regel, 13)}{(11)}}{
    \MyNode{rll}{%
      16. & \textcolor{blue}{\niet{}a} & \\
      & \textcolor{red}{X(5, 16)}}{}
    \pstree{\MyNode{rll}{%
        17. & \textcolor{black}{b\of{}c\imp{}d\en{}e} & \\
        18. & \textcolor{black}{\niet{}(b\of{}c)\of{}(d\en{}e)} &
            (\imp{}-regel,
        17)}{(18)}}{
      \MyNode{rll}{%
        19. & \textcolor{black}{\niet{}(b\of{}c)} & \\
        20. & \textcolor{black}{\niet{}b\en{}\niet{}c} &
            (\of{}-regel, 19)\\
        21. & \textcolor{blue}{\niet{}b} &
            (\en{}-regel, 20)\\
        22. & \textcolor{blue}{\niet{}c} &
            (\en{}-regel, 20)\\
        & \textcolor{red}{X(8, 22)}}{}{
      }
      \MyNode{rll}{%
        23. & \textcolor{black}{d\en{}e} & \\
        24. & \textcolor{blue}{d} & (\en{}-regel, 23)\\
        25. & \textcolor{blue}{e} & (\en{}-regel, 23)\\
        & \textcolor{red}{X(14, 25)}}{}{
      }
    }
  }
  \MyNode{rll}{%
    26. & \textcolor{blue}{g} & \\
    & \textcolor{red}{X(9, 26)}}{}
}
\end{document}





More information about the PSTricks mailing list