我需要幫助來完成樹圖

我需要幫助來完成樹圖

在此輸入影像描述問題:我一直在嘗試完成我開始的樹狀圖(見圖)。

請幫忙。在此輸入影像描述

這就是我所擁有的

\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

你只需要嵌套你的childs:

\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紙還是美國信。可能是後者,但我認為是前者,因為它更窄。

如果你使用forest,有點像你的樹的東西就適合。這不完全是你的樹,因為當單字變得不熟悉時,我失去了輸入內容的耐心,而是開始編造東西。

請注意,切換到 help 的原因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}

如果這還不夠,我建議sidewaysfigurerotating套件中使用或允許節點中換行。

\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}

達到最終水平並減少液體

相關內容