TikZ - 调整单个节点的节点距离

TikZ - 调整单个节点的节点距离

我正在使用 tikz-er2 包绘制 ER 图。在环境中begintikzpicture,有一个可选参数node distance。这对于所有节点都是全局的。现在,如果我给出一个小距离,节点会相交,如果我给出一个平均距离,节点会显得太远。我如何设置单个节点的距离?tikz-er2麦粒肿文件和用户手册可以找到这里。以下是 MWE:

\documentclass[12pt,draft]{article}
\usepackage{tikz-er2}
\begin{document}
\tikzstyle{every entity} = [draw=blue,fill=blue!20,text=red]
\tikzstyle{every attribute} = [fill=yellow!20]
\tikzstyle{every relationship} = [fill=red!20]
\tikzstyle{every edge} = [link]
\begin{tikzpicture}[node distance=8em]
    \node[entity] (student) {Student};
    \node[attribute] (stud-id) [left of=student] {\key{student-id}} edge (student);
    \node[attribute] (name) [above left of=student] {Name} edge (student);
    \node[attribute] (fname) [above left of=name] {First-Name} edge (name);
    \node[attribute] (lname) [above right of=name] {Last-Name} edge (name);
    \node[attribute] (cgpa)  [above right of=student] {CGPA} edge (student);
    \node[relationship] (joins) [right of=student] {joins} edge [total] (student);
    \node[entity] (pgroup) [right of=joins] {Project-Group} edge [<-] (joins);
\end{tikzpicture}
\end{document}

我已启用草稿模式。似乎有一个坏盒子。我该如何将其移除?

在此处输入图片描述

答案1

您可以使用positioningtikz并单独控制每个节点对之间的距离。

\documentclass[12pt,draft]{article}
\usepackage{tikz-er2}
\usetikzlibrary{positioning}
\begin{document}
\tikzstyle{every entity} = [draw=blue,fill=blue!20,text=red]
\tikzstyle{every attribute} = [fill=yellow!20]
\tikzstyle{every relationship} = [fill=red!20]
\tikzstyle{every edge} = [link]
\begin{tikzpicture}%[node distance=8em]
    \node[entity] (student) at (-2,0) {Student};
    \node[attribute] (stud-id) [left = 0.5cm of student] {\key{student-id}} edge (student);
    \node[attribute] (name) [above left = 0.75cm and 0cm of student] {Name} edge (student);
    \node[attribute] (fname) [above left = 0.75cm and 0cm of name] {First-Name} edge (name);
    \node[attribute] (lname) [above right = 0.75cm and 0cm of name] {Last-Name} edge (name);
    \node[attribute] (cgpa)  [above right =0.75cm and 0cm of student] {CGPA} edge (student);
    \node[relationship] (joins) [right = 0.5cm  of student] {joins} edge [total] (student);
    \node[entity] (pgroup) [right = 0.5cm of joins] {Project-Group} edge [<-] (joins);
\end{tikzpicture}
\end{document}

在此处输入图片描述

调整距离以满足您的需要。

相关内容