答案1
你的要求中有一部分直接来自书中——http://mirrors.ibiblio.org/CTAN/graphics/pgf/contrib/tikz-qtree/tikz-qtree-manual.pdf
\documentclass[11pt]{article}
\usepackage{tikz-qtree}
\begin{tikzpicture}
\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode)}}}
\Tree [.S [.NP [.Det the ] [.N cat ] ]
[.VP [.V sat ]
[.PP [.P on ]
[.NP [.Det the ] [.N mat ] ] ] ] ]
\end{tikzpicture}
\end{document}
编辑1
可以通过添加以下选项来移动节点名称[\edge node[xshift=20pt,yshift=5pt]{$y$};
这里y
已经pp
转移
\begin{tikzpicture}
\tikzset{edge from parent/.style={draw, edge from parent path={(\tikzparentnode.south) -- +(0,-8pt) -| (\tikzchildnode)}}}
\Tree [\edge node[xshift=20pt,yshift=5pt]{$y$}; [.NP [.Det the ] [.N cat ] ]
[.VP [.V sat ]
[\edge node[xshift=30pt,yshift=5pt]{$pp$}; [.P on ]
[.NP [.Det the ] [.N mat ] ] ] ] ]
\end{tikzpicture}
编辑2
要求的第一部分已在下面得到回答 - 需要进行一些调整 - 这是来自 2019 年 1 月 23 日的同一网站答案 -https://tex.stackexchange.com/a/525323/197451
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
% use `compat' level 1.11 or higher so coordinates don't have to be
% prefixed with `axis cs:' (any more)
compat=1.11,
}
\begin{document}
\begin{tikzpicture}[
region/.style={
draw=black!50,
dashed,
},
Node/.style={
midway,
red,
},
declare function={
xmin=0;
xmax=12;
ymin=0;
ymax=300;
},
]
\begin{axis}[hide axis,
xlabel={},
ylabel={},
xmin=xmin,
xmax=xmax,
ymin=ymin,
ymax=ymax,
axis background/.style={},
extra x ticks={},
extra y ticks={},
title=title,
]
\draw [region,fill=brown!40] (xmin,ymin) rectangle (8,ymax) node [Node, xshift=-55, yshift=-76] {68\%};
\draw [region,fill=blue!40] (8,ymin) rectangle (10,50) node [Node, xshift=-10, yshift=-9] {5\%};
\draw [region,fill=red!40] (10,ymin) rectangle (xmax,50) node [Node, xshift=-10, yshift=-9] {5\%};
\draw [region,fill=gray!40] (8,50) rectangle (xmax,ymax) node [Node, xshift=-24, yshift=-64] {22\%};
\end{axis}
\end{tikzpicture}
\end{document}
在修改了相同的代码后,OP 可以得到以下内容 ---