为什么在下面的代码中,Father 总是位于 %mother 下面?

为什么在下面的代码中,Father 总是位于 %mother 下面?

我想要的是“父亲在母亲之上”。为什么在下面的代码中,父亲总是在母亲之下?

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

\begin{document}
\newlength\treeheight
\setlength{\treeheight}{\textheight-2cm}
\begin{tikzpicture}[grow=right,anchor=west,
  every node/.style={},
  level 1/.style={sibling distance=\treeheight/2},
  level 2/.style={sibling distance=\treeheight/4},
  level 3/.style={sibling distance=\treeheight/8}]
  % parents
  \node {My Family Tree}[edge from parent fork right]
    child { node {Father}
      child{ node {Paternal Gfather}
        child{ node {Paternal GGfather}}
        child{ node {Paternal GGmother}}
      }
      child{ node {Paternal Gmother}
        child{ node {Maternal GGfather}}
        child{ node {Maternal GGmother}}
      }
    }
    child { node {Mother}
      child{ node {Maternal Gfather}}
      child{ node {Maternal Gmother}}
    }

  ;
  \end{tikzpicture}
\end{document}

答案1

根据 Ignasi 的建议,您应该使用grow'=right而不是grow rightgrow'使用时,会按相反顺序排列子节点。此外,您可能希望inner sep向所有节点添加一些引用,并使用 拆分长节点,align=left就像我做的那样。我还调整了level distance代码中的 以调整级别之间的距离。

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

\begin{document}
\newlength\treeheight
\setlength{\treeheight}{\textheight-2cm}
\begin{tikzpicture}[grow'=right,anchor=west,
  every node/.style={align=left,inner sep=4pt},
  level 1/.style={sibling distance=\treeheight/2},
  level 2/.style={sibling distance=\treeheight/4},
  level 3/.style={sibling distance=\treeheight/8}]
  % parents
  \node[anchor=east] {My Family\\ Tree}[edge from parent fork right,level distance=1in]
    child { node {Father}
      child{ node {Paternal\\ Gfather}
        child{ node {Paternal\\ GGfather}}
        child{ node {Paternal\\ GGmother}}
      }
      child{ node {Paternal\\ Gmother}
        child{ node {Maternal\\ GGfather}}
        child{ node {Maternal\\ GGmother}}
      }
    }
    child { node {Mother}
      child{ node {Maternal\\ Gfather}}
      child{ node {Maternal\\ Gmother}}
    }

  ;
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容