ツリー図を完成させるのに助けが欲しい

ツリー図を完成させるのに助けが欲しい

ここに画像の説明を入力してください質問: 始めたツリー ダイアグラムを完成させようとしています (図を参照)。

助けてください。ここに画像の説明を入力してください

これが私が持っているものです

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
    
    \begin{center}
        \begin{tikzpicture}[level 1/.style={sibling distance=5cm},level 2/.style={sibling distance=4.0cm}]
        \node {1}[edge from parent fork down]
        child { node {2}}
        child { node {3}
            child {node{4} }
            child {node{5}}
        }               
        ;
    \end{tikzpicture}
    \end{center}
    
\end{document}

答え1

比較のために、以下を使用してこれを行う方法を示しますforest

ここに画像の説明を入力してください

\documentclass{article}

\usepackage[edges]{forest}

\begin{document}

\begin{forest}
for tree={forked edge, edge=->, draw, circle, minimum size=8mm, l sep=5mm}
[1, s sep=5cm
    [2]
    [3, s sep=4cm
        [4, s sep=3cm
            [6, s sep=1cm
                [9][10][11]
            ]
            [7]
            [8, s sep=2cm
                [12][13]
            ]
        ]
        [5]
    ]
]
\end{forest}

\end{document}

答え2

s をネストするだけですchild:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
  
  \begin{center}
    \begin{tikzpicture}[level 1/.style={sibling distance=5cm},
      level 2/.style={sibling distance=4.0cm},
      level 3/.style={sibling distance=2.0cm},
      level 4/.style={sibling distance=1.0cm}]
      \node {1}[edge from parent fork down]
      child { node {2}}
      child { node {3}
        child {node{4}
          child {node{6}
            child {node{9}}
            child {node{10}}
            child {node{11}}}
          child {node{7}}
          child {node{8}
            child {node{12}}
            child {node{13}}}}
        child {node{5}}
      }               
      ;
    \end{tikzpicture}
  \end{center}
  
\end{document}

ここに画像の説明を入力してください

囲み数字が必要な場合は、tikzpictureのオプションに以下を追加してください。

every node/.style={draw, circle},

答え3

これは Sandy G の回答に基づいています。A4 を使用しているのか、US レターを使用しているのかはわかりません。おそらく後者ですが、幅が狭いので前者だと思います。

を使用する場合forest、あなたのツリーに少し似たものが適しています。これはあなたのツリーとは少し異なります。なぜなら、単語がわかりにくくなり、コンテンツを入力するのに我慢できなくなり、代わりに何かを作り上げ始めたからです。

に切り替えると役立つ理由はforest、パッケージがデフォルトでよりコンパクトなツリーを生成するためです ( fit=tight)。

\begin{forest}
  % ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
  forked edges,
  for tree={
    edge+=->,
    draw,
    font=\sffamily,
  },
  where={>Ow+P{n children}{isodd(#1)}}{%
    delay={for n=2{calign with current edge}}
  }{},
  [Fluids
    [Ideal Fluids]
    [Real Fluids
      [Non-Newtonian Fluids
        [Time-Independant Fluids
          [Vouch-saving Vanilla][Soliciting Sourdough][Advocating Avocado]
        ]
        [Timeless Thyme]
        [Time-Dependant Fluids
          [Peppermint][Spearmint]
        ]
      ]
      [Newtonian Fluids]
    ]
  ]
\end{forest}

森バージョン

完全なコード:

\documentclass[a4paper]{article}
\usepackage[showframe]{geometry}
% ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
\usepackage[edges]{forest}

\begin{document}

\noindent
\begin{forest}
  % ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
  forked edges,
  for tree={
    edge+=->,
    draw,
    font=\sffamily,
  },
  where={>Ow+P{n children}{isodd(#1)}}{%
    delay={for n=2{calign with current edge}}
  }{},
  [Fluids
    [Ideal Fluids]
    [Real Fluids
      [Non-Newtonian Fluids
        [Time-Independant Fluids
          [Vouch-saving Vanilla][Soliciting Sourdough][Advocating Avocado]
        ]
        [Timeless Thyme]
        [Time-Dependant Fluids
          [Peppermint][Spearmint]
        ]
      ]
      [Newtonian Fluids]
    ]
  ]
\end{forest}

\end{document}

それでも不十分な場合は、パッケージsidewaysfigureから使用するrotatingか、ノード内で改行を許可することをお勧めします。

\begin{forest}
  % ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
  forked edges,
  for tree={
    edge+=->,
    draw,
    font=\sffamily,
    align=center,
  },
  where={>Ow+P{n children}{isodd(#1)}}{%
    delay={for n=2{calign with current edge}}
  }{},
  [Fluids
    [Ideal Fluids]
    [Real Fluids
      [Non-Newtonian Fluids
        [Time-Independant\\Fluids
          [Vouch-saving\\Vanilla][Soliciting\\Sourdough][Advocating\\Avocado]
        ]
        [Timeless\\Thyme]
        [Time-Dependant\\Fluids
          [Peppermint][Spearmint]
        ]
      ]
      [Newtonian Fluids]
    ]
  ]
\end{forest}

複数行ノード付き

さらに良いのは、情報の重複を避けることです。ツリーの上部にはこれらはすべて流体であると記載されているので、なぜ同じことを繰り返す必要Fluidsがあるのでしょうか。余分なものを削除すると、幅があまり狭くならなくても、図がより明確になる可能性があります。

あるいは、もっと冒険したい場合は、反抗的なノードを反転させることもできますが、この方法は適切な場合にのみ使用することをお勧めします (ただし、これが適切なケースに含まれるとは思えません)。

\begin{forest}
  % ateb: https://tex.stackexchange.com/a/707154/ addaswyd o ateb Sandy G: https://tex.stackexchange.com/a/706800/
  forked edges,
  for tree={
    edge+=->,
    draw,
    font=\sffamily,
  },
  where={>Ow+P{n children}{isodd(#1)}}{%
    delay={for n=2{calign with current edge}}
  }{},
  before typesetting nodes={%
    tempcounta/.max={>O{level}}{tree},
    where={> OR= {level}{tempcounta}}{rotate=-90,anchor=parent}{},
  },
  [Fluids
    [Ideal]
    [Real
      [Non-Newtonian
        [Time-Independent
          [Vouch-saving Vanilla][Soliciting Sourdough][Advocating Avocado]
        ]
        [Timeless Thyme]
        [Time-Dependant
          [Peppermint][Spearmint]
        ]
      ]
      [Newtonian]
    ]
  ]
\end{forest}

最終レベルになり、液体が少なくなった

関連情報