ER图关系节点大小调整

ER图关系节点大小调整

CONTRACTED_By我正在尝试(但没有成功)使用以下方法来减少此 ER 模型中关系的大小tikz-er2包裹。它自然地将高度与宽度缩放,但我希望高度更短。有什么方法可以实现吗?(抱歉,这不是尽可能最小的,但我决定复制我拥有的图形。)

\documentclass[12pt]{article}
\usepackage{tikz,tikz-er2}

\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}[node distance=1.5cm]
\tikzset={every entity/.style = {minimum width=1cm,minimum height=0.8cm, text width=1cm,inner sep=1pt},
every attribute/.style = {minimum width=1.2cm,minimum height=0.5cm, text width=1.2cm,inner sep=1pt},
every relationship/.style = {minimum width=1.2cm,minimum height=0.5cm, text width=1.2cm,inner sep=1pt},
every edge/.style = {link}
}

\node[entity] (worker) {WORKER};
\node[attribute] (w1) [above left=1cm of worker,xshift=1cm] {\uline{Number}} edge (worker);
\node[attribute] (w2) [above right=1cm of worker,xshift=-1cm] {Name} edge (worker);
\node[attribute] (w3) [below left=1cm of worker,xshift=1cm] {Title} edge (worker);
\node[attribute] (w4) [below right=1cm of worker,xshift=-1cm] {Salary} edge (worker);

\node[relationship] (worksin) [right=of worker] {WORKS\_IN} edge node[above right] {N} (worker);
\node[attribute] (wn1) [above=of worksin,yshift=-0.5cm] {Responsibility} edge (worksin);
\node[attribute] (wn2) [below=of worksin,yshift=0.5cm] {Duration} edge (worksin);

\node[entity] (project) [right=of worksin] {PROJECT} edge node[above left] {1} (worksin);
\node[attribute] (p1) [above left=1cm of project,xshift=1cm] {\uline{Number}} edge (project);
\node[attribute] (p2) [above=of project] {Project\\Name} edge (project);
\node[attribute] (p3) [above right=1cm of project,xshift=-1cm] {Budget} edge (project);
\node[attribute] (p4) [right= of project] {Location} edge (project);

\node[relationship] (contract) [below=of project] {CONTRACTED\_BY} edge node[above right] {N} (project);
\node[attribute] (c1) [below left=of contract] {Contract\\number} edge (contract);

\node[entity] (client) [below=of contract] {CLIENT} edge node[above right] {1} (contract);
\node[attribute] (cl1) [below left=1cm of client, xshift=1cm] {\uline{Client name}} edge (client);
\node[attribute] (cl2) [below right=1cm of client, xshift=-1cm] {Address} edge (client);

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

您可以aspect使用 键更改该节点的比例aspect。默认情况下,样式中它设置为1。这里我将其更改为2

\documentclass[border=5pt]{standalone}
\usepackage{tikz,tikz-er2}

\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}[node distance=1.5cm]
\tikzset={every entity/.style = {minimum width=1cm,minimum height=0.8cm, text width=1cm,inner sep=1pt},
every attribute/.style = {minimum width=1.2cm,minimum height=0.5cm, text width=1.2cm,inner sep=1pt},
every relationship/.style = {minimum width=1.2cm,minimum height=0.5cm, text width=1.2cm,inner sep=1pt},
every edge/.style = {link}
}

\node[entity] (worker) {WORKER};
\node[attribute] (w1) [above left=1cm of worker,xshift=1cm] {\uline{Number}} edge (worker);
\node[attribute] (w2) [above right=1cm of worker,xshift=-1cm] {Name} edge (worker);
\node[attribute] (w3) [below left=1cm of worker,xshift=1cm] {Title} edge (worker);
\node[attribute] (w4) [below right=1cm of worker,xshift=-1cm] {Salary} edge (worker);

\node[relationship] (worksin) [right=of worker] {WORKS\_IN} edge node[above right] {N} (worker);
\node[attribute] (wn1) [above=of worksin,yshift=-0.5cm] {Responsibility} edge (worksin);
\node[attribute] (wn2) [below=of worksin,yshift=0.5cm] {Duration} edge (worksin);

\node[entity] (project) [right=of worksin] {PROJECT} edge node[above left] {1} (worksin);
\node[attribute] (p1) [above left=1cm of project,xshift=1cm] {\uline{Number}} edge (project);
\node[attribute] (p2) [above=of project] {Project\\Name} edge (project);
\node[attribute] (p3) [above right=1cm of project,xshift=-1cm] {Budget} edge (project);
\node[attribute] (p4) [right= of project] {Location} edge (project);

\node[relationship,aspect=2] (contract) [below=of project,] {CONTRACTED\_BY} edge node[above right] {N} (project);
\node[attribute] (c1) [below left=of contract] {Contract\\number} edge (contract);

\node[entity] (client) [below=of contract] {CLIENT} edge node[above right] {1} (contract);
\node[attribute] (cl1) [below left=1cm of client, xshift=1cm] {\uline{Client name}} edge (client);
\node[attribute] (cl2) [below right=1cm of client, xshift=-1cm] {Address} edge (client);

\end{tikzpicture}

\end{document}

代码输出

答案2

由于缺少 tikz-er2,我无法编译您的代码,但查看您的代码,由于文本长度,“CONTRACTED_BY”的框更大。我假设如果您减小文本的大小,框也会变小。您可以尝试以下操作:

\node[relationship] (contract) [below=of project] {\small CONTRACTED\_BY} edge node[above right] {N} (project);

相关内容