基本上,我想在两个树边之间创建一条(虚线)线。我尝试了一点小技巧,在两个隐藏节点之间手动创建了一条这样的线。问题是,我没有隐藏它们!连接边之间总是有一点空间,我尝试过的任何参数似乎都没有帮助(半径、树节点大小等)。
\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}
答案1
将 nodesep 设置为零:
\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}
或者使用以下选项offset
:
\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}