![二项式树 tikz](https://linux22.com/image/464383/%E4%BA%8C%E9%A1%B9%E5%BC%8F%E6%A0%91%20tikz.png)
帮助!我是 LateX 的新手,我想通过放大这些特定点的大小,在点 A 上添加红色,在树的最高点上添加蓝色,从而重现这棵树。附件是我到目前为止所做的。我提前感谢您的帮助。祝大家有美好的一天!
\tikzset{pics/arrow/.style={/tikz/sloped, /tikz/allow upside down,code=\pgfarrowdraw{#1}}, pics/arrow/.default=>}
\begin{tikzcd}[
dot/.style={circle, fill, draw, inner sep=+0pt, minimum size=+3.5pt,
/utils/exec=\ifnum\pgfmatrixcurrentcolumn<4 \rar\arrow[ur]\arrow[dr]\fi},
/tikz/reddot/.style ={circle, fill=red, minimum size=+12.5pt},
/tikz/bluedot/.style ={circle, fill=blue, minimum size=+12.5pt},
/tikz/a/.style ={commutative diagrams/dot, label={above:{#1}}},
/tikz/ar/.style ={commutative diagrams/dot, label={[xshift=+10pt]above:{#1}}},
/tikz/al/.style ={commutative diagrams/dot, label={[xshift=-10pt]above:{#1}}},
/tikz/arr/.style ={commutative diagrams/dot, label={[xshift=+25pt]above:{#1}}},
/tikz/bb/.style ={commutative diagrams/dot, label={[align=center]below:{#1\\ }}},
/tikz/b/.style={commutative diagrams/dot, label={below:{#1}}},
/tikz/bl/.style={commutative diagrams/dot, label={[xshift=-10pt]below:{#1}}},
/tikz/br/.style={commutative diagrams/dot, label={[xshift=+10pt]below:{#1}}},
/tikz/brrr/.style={commutative diagrams/dot, label={[xshift=+40pt]below:{#1}}},
/tikz/bbl/.style={commutative diagrams/dot, label={[align=center, xshift=-10pt]below:{#1\\ }}},
/tikz/bbr/.style={commutative diagrams/dot, label={[align=center, xshift=+10pt]below:{#1\\ }}},
/tikz/bbrrr/.style={commutative diagrams/dot, label={[align=center, xshift=+40pt]below:{#1\\ }}},
/tikz/l/.style={commutative diagrams/dot, label={ left:{#1}}},
/tikz/r/.style={commutative diagrams/dot, label={right:{#1}}},
arrows={-Stealth},column sep={3cm,between origins}, row sep={1.33cm,between origins},cells={nodes={fill, circle, minimum size=3.5pt, inner sep=0pt, font=\large}}]
& & & |[bluedot, ar=70.00, br=70.00, bbr=0.00]| \\
& & |[a=62.99, b=62.99, bb=3.36]|\arrow[ur]\arrow[dr] & \\
& |[a=56.12, b=56.12, bb=4.68]|\arrow[ur]\arrow[dr] & & |[arr=56.12, br=62.99, bbr=6.87,brrr=56.12, bbrrr=0.00]| \\
|[al=50.00, bl=50.00, bbl=5.47]|\arrow[ur]\arrow[dr] & & |[reddot, a=50.00, bl=56.12, bbl=6.12, br=50.00, bbr=2.66]|\arrow[ur]\arrow[dr] & \\
& |[a=44.55, b=50.00, bb=6.38]|\arrow[ur]\arrow[dr] & & |[arr=44.55, br=56.12, bbr=11.57, brrr=50.00, bbrrr=5.45]| \\
& & |[a=39.69, b=50.00, bb=10.31]|\arrow[ur]\arrow[dr] & \\
& & & |[ar=35.36, br=50.00, bbr=14.64]|
\end{tikzcd}
\begin{tikzcd}[
dot/.style={circle, fill, draw, inner sep=+0pt, minimum size=+3.5pt,
/utils/exec=\ifnum\pgfmatrixcurrentcolumn<4 \rar\urar\drar\fi},
/tikz/a/.style ={commutative diagrams/dot, label={above:{#1}}},
/tikz/al/.style ={commutative diagrams/dot, label={[xshift=-10pt]above:{#1}}},
/tikz/bb/.style ={commutative diagrams/dot, label={[align=center]below:{#1\\second line}}},
/tikz/b/.style={commutative diagrams/dot, label={below:{#1}}},
/tikz/bl/.style={commutative diagrams/dot, label={[xshift=-10pt]below:{#1}}},
/tikz/bbl/.style ={commutative diagrams/dot, label={[align=center, xshift=-10pt]below:{#1\\second line}}},
/tikz/bbr/.style={commutative diagrams/dot, label={[align=center]below right:{#1\\second line}}},
/tikz/l/.style={commutative diagrams/dot, label={ left:{#1}}},
/tikz/r/.style={commutative diagrams/dot, label={right:{#1}}},
arrows={-Stealth},column sep={3cm,between origins}, row sep={1.33cm,between origins},cells={nodes={fill, circle, minimum size=3.5pt, inner sep=0pt, font=\large}}]
& & & |[fill=blue,minimum size=12.5,"70.70" above right,"70.70" below right, "0.00" below right]| \\
& & |["62.99" above,"62.99" below, "3.36" below]|\arrow[ur]\arrow[dr] & \\
& |[a=56.12, b=56.12, bb=4.68]|\arrow[ur]\arrow[dr] & & |["56.12" above right,"62.99" below left,"6.87" below left, "56.12" below right,"0.00" below right]| \\
|[al=50.00, bl=50.00, bbl=5.47]|\arrow[ur]\arrow[dr] & & |[fill=red,minimum size=12.5,"50.00" above,"56.12" below left,"6.12" below left, "50.00" below right,"2.66" below right]|\arrow[ur]\arrow[dr] & \\
& |["44.55" above,"50.00" below, "6.38" below]|\arrow[ur]\arrow[dr] & & |["44.55" above right,"56.12" below left,"11.57" below left, "50.00" below right,"5.45" below right]| \\
& & |["39.69" above,"50.00" below, "10.31" below]|\arrow[ur]\arrow[dr] & \\
& & & |["35.36" above right,"50.00" below right, "14.64" below right]|
\end{tikzcd}
答案1
使用istgame
包裹:
放大的色点是使用tzplot
包裹。
\documentclass{standalone}
\usepackage{tzplot} % for enlarged color points (\tzdot*)
\usepackage{istgame} % to draw tree
\usepackage{makecell}
\begin{document}
\begin{istgame}[font=\scriptsize]
\setistgrowdirection'{east}
\setxtshowmidarrows<.95>
\xtShowMidArrows
\xtShowEndPoints
\xtdistance{40mm}{30mm}
\istroot(0)<180>{\makecell[r]{50.00\\50.00\\5.47}}
\istb \istb \endist
\istroot(a1)(0-1)<90>{56.12}
\istb \istb \endist
\xtOwner(a1){\makecell[r]{56.12\\4.68}}[below=3pt]
\istroot(a2)(0-2)<90>{44.55}
\istb \istb \endist
\xtOwner(a2){\makecell[r]{50.00\\6.38}}[below]
\istroot(b1)(a1-1){62.99}
\istb{}{\makecell[r]{70.0\\70.0\\0.0}}
\istb{}{\makecell[c]{56.12\\
62.99\quad 56.12\\
\hphantom{0}6.87\quad \hphantom{0}0.00}
}
\endist
\xtOwner(b1){\makecell[r]{62.99\\3.36}}[below]
\istroot(b2)(a1-2){50.00}
\istb \istb \endist
\xtOwner(b2){\makecell[r]{56.12\quad 50.00\\
\hphantom{0}6.12\quad
\hphantom{0}2.66}
}[below=7pt]
\istroot(b3)(a2-1)<0>{\quad A}
\istb \istb \endist
\istroot(b4)(a2-2){39.69}
\istb{}{\makecell[c]{44.55\\
56.12\quad 50.00\\
11.57\quad \hphantom{0}5.47}
}
\istb{}{\makecell[r]{35.36\\50.00\\14.64}}
\endist
\xtOwner(b4){\makecell[r]{50.00\\10.31}}[below]
%% points using the "tzplot" package:
\tzdot*[red](b3)(5pt) % red point, size=5pt
\tzdot*[blue](b1-1)(5pt) % blue point, size=5pt
\end{istgame}
\end{document}
答案2
适应我的类似答案但是,我不是使用一串产生各种标签的键,而是quotes
使用一个使用非常具体的“d 标签”(d 是方向?)的库,将其内容放入环境中tabular
。
键^
、、v
和<
的>
设置代表above
、、below
和,left
但right
它们的值指定了环境中的列数tabular
。
&
作为底层 TikZ 矩阵的活动版本以及正常版本&
(catcode 4),这有点混乱,如果ampersand replacement
是不是用过的。
该siunitx
包也不喜欢活动&
,我不得不求助于基本r
列。
不清楚你的意思
树的最高点
所以我把 A 点改为红色。
如果您需要某个点更大,您可以minimum size
只使用该点并使用比 更大的值3.5pt
(此处在环境选项中使用tikzcd
)。将点设为蓝色也不成问题。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{cd, quotes}
\makeatletter
\def\amp@normal{&}{\catcode`\&=13 \gdef\makeactiveampersandnormal{\let&\amp@normal}}
\makeatother
\newcommand*\mc[1]{\multicolumn{2}{c}{#1}}
\tikzset{
pics/arrow/.style={/tikz/sloped, /tikz/allow upside down, code=\pgfarrowdraw{#1}}, pics/arrow/.default=>,
@create d label/n/.initial=1,
quotes mean d label/.style={
node quotes mean={
label={[every d label,create d label shortcuts,##2]\makeactiveampersandnormal\setlength\tabcolsep{.5\tabcolsep}%
\begin{tabular}{@{}*{\pgfkeysvalueof{/tikz/@create d label/n}}{r}@{}}##1\end{tabular}}}},
create d label shortcuts/.style={
^/.style={label position=90, @create d label/n/.expanded={##1}},^/.default=\pgfkeysvalueof{/tikz/@create d label/n},
v/.style={label position=-90,@create d label/n/.expanded={##1}},v/.default=\pgfkeysvalueof{/tikz/@create d label/n},
</.style={label position=180,@create d label/n/.expanded={##1}},>/.default=\pgfkeysvalueof{/tikz/@create d label/n},
>/.style={label position=0, @create d label/n/.expanded={##1}},</.default=\pgfkeysvalueof{/tikz/@create d label/n}},
every d label/.style={rectangle, inner sep=+0pt}}
\begin{document}
\begin{tikzcd}[
/tikz/dot/.style={circle, fill, draw, inner sep=+0pt, minimum size=+3.5pt,
/utils/exec=\ifnum\pgfmatrixcurrentcolumn<4 \urar\drar\fi},
arrows={-, /tikz/every to/.append style={edge node={pic[pos=.95]{arrow=Stealth}}}},
cells={nodes={dot, quotes mean d label}},
column sep={3cm,between origins}, row sep={1.5cm,between origins},
label distance=2ex,
]
& & & |["70.00 \\ 70.00 \\ 0.00" >]| \\
& & |["62.99" ^, "62.99 \\ 3.36" v]| \\
& |["56.12" ^, "56.12 \\ 4.68" v]|
& & |["\mc{56.12} \\ 62.99 & 56.12 \\ 6.87 & 0.00" >=2]| \\
|["50.00 \\ 50.00 \\ 5.47" <]|
& & |["50.00"^, "56.12 & 50.00 \\ 6.12 & 2.66" {v=2, below=1ex}, label=right:A, red]| \\
& |["44.55"^, "50.00 \\ 6.38" v]|
& & |["\mc{44.55} \\ 56.12 & 50.00 \\ 11.57 & 5.45" >=2]| \\
& & |["36.69"^, "50.00 \\ 10.31" v]| \\
& & & |["33.36 \\ 50.00 \\ 14.65" >]|
\end{tikzcd}
\end{document}
输出
答案3
我认为tikz-cd
这可能不是合适的工具。我建议使用普通的tikz
。以下是执行此操作的一种方法:
您可以使用该positioning
库来精确放置您的节点,这样它们就不会受到标签的影响。
dot
可以通过以下方式设置带有颜色参数的样式tikzset
:
\tikzset{
dot/.style={draw, #1, fill=#1, circle, inner sep=0pt, minimum size=4pt},
dot/.default={black}
}
然后放置节点的代码将如下所示:
\begin{tikzpicture}[every node/.style={dot}, node distance=1cm and 3cm]
\node(A){};
\node[above right=of A](B1){};
\node[below right=of A](B2){};
\node[above right=of B1](C1){};
\node[below right=of B1, dot=red](C2){};
\node[below right=of B2](C3){};
\node[above right=of C1, dot=blue](D1){};
\node[below right=of C1](D2){};
\node[above right=of C3](D3){};
\node[below right=of C3](D4){};
\end{tikzpicture}
接下来我们可以画箭头。你的图表中有一种特定的箭头。形状是Stealth
,它不完全在线的末端。你可以使用decorations.markings
和来做到这一点arrows.meta
。添加到你的tikzset
:
arrowmark/.style={postaction={decorate, decoration={markings, mark=at position .9 with {\arrow{Stealth}}}}}
然后\draw
带有选项的命令arrowmark
可以绘制你的箭头:
\draw[arrowmark](A)--(B1); \draw[arrowmark](A)--(B2);
\draw[arrowmark](B1)--(C1); \draw[arrowmark](B1)--(C2);
\draw[arrowmark](B2)--(C2); \draw[arrowmark](B2)--(C3);
\draw[arrowmark](C1)--(D1); \draw[arrowmark](C1)--(D2);
\draw[arrowmark](C2)--(D2); \draw[arrowmark](C2)--(D3);
\draw[arrowmark](C3)--(D3); \draw[arrowmark](C3)--(D4);
可以使用 向节点添加标签label={[<options>]<direction>:<contents>}
。如果愿意,您可以使用角度作为方向,也可以选择更改label distance
。您可以向一个节点添加多个标签。\\
如果您在选项中添加(或任何对齐),则允许使用多行标签来分隔行align=right
。因此,您的前几个节点将如下所示:
\node[label={left:50.00\\50.00\\5.47}](A){};
\node[above right=of A, label={below:56.12\\4.68}, label={above:56.12}](B1){};
\node[below right=of A, label={below:50.00\\6.38}, label={above:44.55}](B2){};
这是完整的代码。我添加了“幻影数字”命令,\phdi
以使最右侧标签上的间距正确。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, decorations.markings, arrows.meta}
\tikzset{
dot/.style={draw, #1, fill=#1, circle, inner sep=0pt, minimum size=4pt},
dot/.default={black},
arrowmark/.style={postaction={decorate, decoration={markings, mark=at position .9 with {\arrow{Stealth}}}}}
}
\newcommand{\phdi}{\phantom{0}}
\begin{document}
\begin{tikzpicture}[every node/.style={dot}, node distance=1cm and 3cm, align=right, font=\scriptsize]
\node[label={left:50.00\\50.00\\5.47}](A){};
\node[above right=of A, label={below:56.12\\4.68}, label={above:56.12}](B1){};
\node[below right=of A, label={below:50.00\\6.38}, label={above:44.55}](B2){};
\node[above right=of B1, label={below:62.99\\3.36}, label={above:62.99}](C1){};
\node[below right=of B1, dot=red, label={[label distance=2.5mm]-120:56.12\\6.12}, label={[label distance=2.5mm]-60:50.00\\2.66}, label={above:50.00}, label={[label distance=2.5mm]right:A}](C2){};
\node[below right=of B2, label={below:50.00\\10.31}, label={above:39.69}](C3){};
\node[above right=of C1, dot=blue, label={right:70.00\\70.00\\0.00}](D1){};
\node[below right=of C1, label={[align=center]right:56.12\\62.99\quad56.12\\\phdi6.87\quad\phdi0.00}](D2){};
\node[above right=of C3, label={[align=center]right:44.55\\56.12\quad50.00\\11.57\quad\phdi5.45}](D3){};
\node[below right=of C3, label={right:35.36\\50.00\\14.64}](D4){};
\draw[arrowmark](A)--(B1); \draw[arrowmark](A)--(B2);
\draw[arrowmark](B1)--(C1); \draw[arrowmark](B1)--(C2);
\draw[arrowmark](B2)--(C2); \draw[arrowmark](B2)--(C3);
\draw[arrowmark](C1)--(D1); \draw[arrowmark](C1)--(D2);
\draw[arrowmark](C2)--(D2); \draw[arrowmark](C2)--(D3);
\draw[arrowmark](C3)--(D3); \draw[arrowmark](C3)--(D4);
\end{tikzpicture}
\end{document}