Tikz 树 - 文本在垂直线上旋转 90 度

Tikz 树 - 文本在垂直线上旋转 90 度

我一直在尝试制作概率树,我认为我几乎已经做得相当不错了,但是向下的垂直线上的标签与线一起倾斜,导致文本旋转了 90 度。所以我的问题是,我是否可以旋转标签,同时选择一些标签使其具有正常方向?

usepackage{tikz}
\usetikzlibrary{trees}


% Define styles for bags and leafs
\tikzstyle{deck} = [text width=4em, text centered]
\tikzstyle{end} = [circle, minimum width=3pt,fill, inner sep=0pt]

% Set the overall layout of the tree
\tikzstyle{level 1}=[level distance=3.5cm, sibling distance=3.5cm]
\tikzstyle{level 2}=[level distance=3.5cm, sibling distance=2cm]

\begin{document}

\begin{tikzpicture}[sloped]
\node[deck] {First card}
        child {
                node[deck] {Second card}
                child {
                        node[end, label=below: {$\frac{1}{4} \cdot \frac{1}{3}$}] {}
                        edge from parent 
                        node[above] {$\frac{1}{3}$}
                        node[below] {Q $\spadesuit$}
                }
                child {
                        node[end, label=below:  {$\frac{1}{4} \cdot \frac{1}{3}$}] {}
                        edge from parent 
                        node[left] {$\frac{1}{3}$}
                        node[right] {Q $\heartsuit$}
                }
                child {
                        node[end, label=below:  {$\frac{1}{4} \cdot \frac{1}{3}$}] {}
                        edge from parent 
                        node[above] {$\frac{1}{3}$}
                        node[below] {A $\heartsuit$}
        }
                edge from parent
                node[above] {$\frac{1}{4}$}
                node[below] {A $\spadesuit$}
        }
        child {
                node[deck] {Second card}
                child {
                        node[end, label=below:  {$\frac{1}{4} \cdot \frac{1}{3}$}] {}
                        edge from parent 
                        node[above] {$1$}
                        node[below] {A $\spadesuit$}
                }
                child {
                        node[end, label=below:  {$\frac{1}{4} \cdot \frac{1}{3}$}] {}
                        edge from parent 
                        node[above] {$0$}
                        node[below] {$\neg$A $\spadesuit$}
        }
                edge from parent
                node[above] {$\frac{1}{4}$}
                node[below] {A $\heartsuit$}
        }
        child {
                node[deck] {Second card}
                child {
                        node[end, label=below: {$\frac{1}{4} \cdot \frac{1}{3}$}] {}
                        edge from parent 
                        node[above] {$1$}
                        node[below] {A $\spadesuit$}
                }
                child {
                        node[end, label=below:  {$\frac{1}{4} \cdot \frac{1}{3}$}] {}
                        edge from parent 
                        node[above] {$0$}
                        node[below] {$\neg$A $\spadesuit$}
        }
                edge from parent
                node[above] {$\frac{2}{4}$}
                node[below] {$\neg$A}
        };
\end{tikzpicture}

\end{document}

在此处输入图片描述

任何帮助将非常感激!

答案1

我尝试使用istgame包裹:

在此处输入图片描述

\documentclass[tikz]{standalone}
    
\usepackage{istgame}
\usepackage{makecell}    
\def\vcard#1{\makecell{#1}}

\begin{document}

\begin{istgame}
\tikzset{oval node/.style={ellipse node,draw=none}}
\xtdistance{35mm}{45mm}
\istrooto(0){\vcard{First\\card}}
  \istB{\frac14}[above,sloped]{A \spadesuit}[below,sloped]
  \istB{A \heartsuit}[below,sloped]{\frac14}[right]
  \istB{\neg A}[bl]{\frac24}[ar]
  \endist
\xtdistance{35mm}{20mm}
\istrooto(1)(0-1){\vcard{Second\\card}}
  \istB{\frac13}[above,sloped]{Q \spadesuit}[below,sloped]{\frac14\cdot\frac13}
  \istB{\frac13}[left]{Q \heartsuit}[above,sloped]{\frac14\cdot\frac13}
  \istB{\frac13}[above,sloped]{A \heartsuit}[below,sloped]{\frac14\cdot\frac13}
  \endist
\istrooto(2)(0-2){\vcard{Second\\card}}
  \istB{1}[l]{A \spadesuit}[below,sloped]{\frac14\cdot 1}
  \istB{0}[r]{\neg A \spadesuit}[below,sloped]{\frac14\cdot 0}
  \endist
\istrooto(3)(0-3){\vcard{Second\\card}}
  \istB{1}[l]{A \spadesuit}[below,sloped]{\frac14\cdot 1}
  \istB{0}[r]{\neg A \spadesuit}[below,sloped]{\frac14\cdot 0}
  \endist
\end{istgame}

\end{document}

相关内容