给 tikz 树的树枝上色

给 tikz 树的树枝上色

我想要给下面这棵树的树枝上色:

\documentclass[12pt,a4paper]{article}   
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\tikzset{every tree node/.style={align=center,anchor=north}}
\usepackage[normalem]{ulem}

\begin{document}

\begin{tikzpicture}
\Tree
[.S 
  [.DP E 
    [.NP PRO 
        [.NP $\lambda_1$ 
            [.NP S  
                [.S 
                    [.DP    [.D\\the ] [.N\\pictures ]] 
                    [.VP    [.V\\display ] 
                            [.DP [.D\\the ] [.NP [.N\\man ] 
                                            [.S   ]
                                            ]
                            ]
                    ]
                ]
            ]
        ]
    ]
  ]
  [.VP [.V ] [.DP ]]
]

\end{tikzpicture}

\end{document}

代码输出

我怎样才能使某些分支(即连接组成部分的树的线)变成一种颜色(并将所有节点标签变成它们所在分支的颜色),而将其他分支变成另一种颜色?例如,我怎样才能使最右边最上面的直接 VP 组成部分变成蓝色,而其他组成部分变成绿色?请注意,我希望在 tikz-qtree 中执行此操作,而不是在森林中执行此操作。

答案1

像这样吗?

\documentclass[12pt,a4paper]{article}   
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\tikzset{every tree node/.style={align=center,anchor=north}, edge from parent/.style={draw, green}}
\usepackage[normalem]{ulem}

\begin{document}

\begin{tikzpicture}
\Tree
[.S 
  [.DP E 
    [.NP PRO 
        [.NP $\lambda_1$ 
            [.NP S  
                [.S 
                    [.DP    [.D\\the ] [.N\\pictures ]] 
                    [.VP    [.V\\display ] 
                            [.DP [.D\\the ] [.NP [.N\\man ] 
                                            [.S   ]
                                            ]
                            ]
                    ]
                ]
            ]
        ]
    ]
  ]
  \edge[blue]; [.VP [.V ] [.DP ]]
]

\end{tikzpicture}

\end{document}

您可以\edge[...];在节点前面放置它并以任何您想要的方式设置它的样式来覆盖默认样式(可以类似地使用\node[...]{...},请参阅手册第 6-8 页)。

在此处输入图片描述

编辑:将所有文本涂成与其父边相同的颜色:

\documentclass[12pt,a4paper]{article}   
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\tikzset{every tree node/.style={align=center, anchor=north, green!50!black}, edge from parent/.style={draw, green}}
\usepackage[normalem]{ulem}

\begin{document}

\begin{tikzpicture}
\Tree
[.S 
  [.DP E 
    [.NP PRO 
        [.NP $\lambda_1$ 
            [.NP S  
                [.S 
                    [.DP    [.D\\the ] [.N\\pictures ]] 
                    [.VP    [.V\\display ] 
                            [.DP [.D\\the ] [.NP [.N\\man ] 
                                            [.S   ]
                                            ]
                            ]
                    ]
                ]
            ]
        ]
    ]
  ]
  \edge [blue]; [.\node [blue] {VP}; [.V ] [.DP ]]
]

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

像这样?

蓝绿色的树

\documentclass[12pt,a4paper]{article}
\usepackage{tikz-qtree}
\usepackage{tikz-qtree-compat}
\tikzset{every tree node/.style={align=center,anchor=north}}

\begin{document}

\begin{tikzpicture}[text=green!50!black]
\Tree
[.S
  [.DP E
    [.NP PRO
        [.NP $\lambda_1$
            [.NP S
                [.S
                    [.DP    [.D\\the ] [.N\\pictures ]]
                    [.VP    [.V\\display ]
                            [.DP [.D\\the ] [.NP [.N\\man ]
                                            [.S   ]
                                            ]
                            ]
                    ]
                ]
            ]
        ]
    ]
  ]
  [.{\color{blue}VP} [.V ] [.DP ]]
]

\end{tikzpicture}

\end{document}

相关内容