MWE 与forest

MWE 与forest

我正在尝试绘制一个如下所示的简单图形,但一直无法实现。如果我让节点没有任何间距,则边长会出错,如果我让它们正确,则父边与子边之间会有间距。非常感谢您的帮助。

在此处输入图片描述

答案1

发布的图形可以通过以下方式轻松生成foresttikz

MWE 与forest

\documentclass[border=2pt]{standalone}
\usepackage{forest}

\begin{document}
\begin{forest}
  for tree={l+=1.5cm,}
  [,parent anchor=south,
    [\phantom{300000},parent anchor=north,child anchor=north,edge label={node[midway,left]{name}}
      [``Joe'',parent anchor=north,edge label={node[midway,left]{first}}]
      [``Blow'',ignore edge,edge label={node[midway,right]{last}}]
    ]
    [``UW'',edge label={node[near end]{institution}}]
    [300000,edge label={node[midway,right]{salary}}]
  ]
\end{forest}
\end{document}

MWE 与tikz

\documentclass[border=2pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[level distance=2cm]
  \coordinate
    child{
      child{node{``Joe''} edge from parent node[left]{first}}
      child{node{``Blow''} edge from parent node[right]{last}}
      edge from parent node[left]{name}
    }
    child{node{``UW''} edge from parent node[near end]{institution}}
    child{node{300000} edge from parent node[right]{salary}}
  ;
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容