在 Latex 中对齐树形图

在 Latex 中对齐树形图

我拼命尝试对齐此树形图。使用命令align=Center。我将其作为以下代码中节点的选项插入,但没有任何成功。我如何使此树形图居中或至少使其左对齐。

在此处输入图片描述

\tikzset{
  % Two node styles for game trees: solid and hollow
   solid node/.style={circle,draw,inner sep=1.2,fill=black},
  hollow node/.style={circle,draw,inner sep=1.2},
}

% macro for entering payoffs
\newcommand\payoff[1]{
  $\begin{pmatrix} #1 \end{pmatrix}$
}

\begin{tikzpicture}[font=\footnotesize]

  \tikzset{
    level 1/.style={level distance=15mm,sibling distance=50mm},
    level 2/.style={level distance=12mm,sibling distance=12mm},
    level 3/.style={level distance=15mm,sibling distance=30mm},
  }

  \node[hollow node,label=above:{Car ownership Decision}]{}
    child{node[solid node,label=left:{Auto 0}]{}
        child{node[solid node,label=left:{Walk}]{}}  
        child{node[solid node,label=left:{Bike}]{}}
        child{node[solid node,label=left:{Metro}]{}}
        child{node[solid node,label=left:{Taxi}]{}}}
    child{node[solid node,label=right:{auto 2}]{}               child{node[solid node,label=left:{Walk}]{}}  
        child{node[solid node,label=left:{Bike}]{}}
        child{node[solid node,label=left:{Metro}]{}}
        child{node[solid node,label=left:{Car}]{}}  }   
child{node[solid node,label=right:{auto 2}]{}               child{node[solid node,label=left:{Walk}]{}}  
        child{node[solid node,label=left:{Bike}]{}}
        child{node[solid node,label=left:{Metro}]{}}
        child{node[solid node,label=left:{Car}]{}}  }       
        child{node[solid node,label=right:{..}]{} }



  ;
    \end{tikzpicture}

答案1

假设您使用像 article 这样的标准类,那么问题就是树太宽了。您可以稍微更改布局和sibling distances 来解决这个问题。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\begin{figure}
\centering
\tikzset{
  % Two node styles for game trees: solid and hollow
   solid node/.style={circle,draw,inner sep=1.2,fill=black},
  hollow node/.style={circle,draw,inner sep=1.2},
}

% macro for entering payoffs
\newcommand\payoff[1]{
  $\begin{pmatrix} #1 \end{pmatrix}$
}

\begin{tikzpicture}[font=\footnotesize]

  \tikzset{
    level 1/.style={level distance=15mm,sibling distance=32mm},
    level 2/.style={level distance=12mm,sibling distance=7.5mm},
  }

  \node[hollow node,label=above:{Car ownership Decision}]{}
    child{node[solid node,label=left:{Auto 0}]{}
        child{node[solid node,label=below:{Walk}]{}}  
        child{node[solid node,label=below:{Bike}]{}}
        child{node[solid node,label=below:{Metro}]{}}
        child{node[solid node,label=below:{Taxi}]{}}}
    child{node[solid node,label=right:{auto 2}]{}               
        child{node[solid node,label=below:{Walk}]{}}  
        child{node[solid node,label=below:{Bike}]{}}
        child{node[solid node,label=below:{Metro}]{}}
        child{node[solid node,label=below:{Car}]{}}  }   
child{node[solid node,label=right:{auto 2}]{}               
        child{node[solid node,label=below:{Walk}]{}}  
        child{node[solid node,label=below:{Bike}]{}}
        child{node[solid node,label=below:{Metro}]{}}
        child{node[solid node,label=below:{Car}]{}}  }       
        child{node[solid node,label=left:{\dots}]{} }  ;
\end{tikzpicture}
\caption{A centered tree.}
\end{figure}
\end{document}

在此处输入图片描述

我个人更喜欢森林。

\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{figure}
\centering
\tikzset{
  % Two node styles for game trees: solid and hollow
   solid node/.style={circle,draw,inner sep=1.2,fill=black},
  hollow node/.style={circle,draw,inner sep=1.2},
}
\begin{forest}
 for tree={solid node,s sep+=1.5em,l sep+=3em},
 [,hollow node,label=above:{Car ownership Decision}
  [,label=left:{Auto 0}
   [,label=below:{Walk}]
   [,label=below:{Bike}]
   [,label=below:{Metro}]
   [,label=below:{Taxi}]
  ]
  [,label=left:{Auto 1}
   [,label=below:{Walk}]
   [,label=below:{Bike}]
   [,label=below:{Metro}]
   [,label=below:{Taxi}]
  ]
  [,label=left:{Auto 2}
   [,label=below:{Walk}]
   [,label=below:{Bike}]
   [,label=below:{Metro}]
   [,label=below:{Taxi}]
  ]
  [,phantom]
  [,label=right:{\dots}]
 ]
\end{forest}
\caption{A centered tree.}
\end{figure}
\end{document}

在此处输入图片描述

答案2

使用istgame包裹:

在此处输入图片描述

\documentclass{standalone}

\usepackage{istgame}

\begin{document}

\begin{istgame}[scale=1,font=\footnotesize]
\xtShowEndPoints
\setistmathTF000
\xtdistance{15mm}{32mm}
\istroot(0)[initial node]{Car ownership Decision}
  \istb  \istb  \istb  \istb  \endist
\xtdistance{12mm}{7.5mm}
\istroot(1)(0-1)<180>{Auto 0}
  \istb{}{Walk} \istb{}{Bike} \istb{}{Metro} \istb{}{Car} \endist
\istroot(2)(0-2)<0>{Auto 2}
  \istb{}{Walk} \istb{}{Bike} \istb{}{Metro} \istb{}{Car} \endist
\istroot(3)(0-3)<0>{Auto 3}
  \istb{}{Walk} \istb{}{Bike} \istb{}{Metro} \istb{}{Car} \endist
\istroot(4)(0-4)<0>{$\dots$}
  \endist
\end{istgame}

\end{document}

相关内容