
我正在為我的學生創建工作表。這是關於 ER 圖的。使用 Word 相對容易,但看起來不太好;)
我已經知道如何建立 ER 圖。我想要的是學生必須填寫的欄位。這是我的程式碼:
\documentclass[10pt,letterpaper]{article}
\usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}
\usepackage{tikz-er2}
\usepackage{adjustbox}
\usetikzlibrary{shadows,positioning}
\begin{document}
\tikzset{every entity/.style={top color=white,bottom color=blue!30,draw=blue!50!black!100,drop shadow},
every attribute/.style = {top color=white, bottom color=yellow!20,
draw=yellow, drop shadow},
every relationship/.style ={top color=white, bottom color=red!20,
draw=red!50!black!100, drop shadow},
every edge/.style = {link},
every isa/.style = {top color=white, bottom color=green!20,
draw=green!50!black!100, drop shadow},
}
\begin{adjustbox}{width=\columnwidth,center}
\begin{tikzpicture}[node distance=8em]
\node[entity] (student) {Kunde};
\node[attribute] (stud-id) [left = of student] {\key{KNR}} edge (student);
\node[attribute] (name) [above = of student] {Name} edge (student);
\node[relationship] (joins) [right = of student] {kauft} edge (student);
\node[entity] (pgroup) [right = of joins] {Artikel} edge (joins);
\node[attribute] (group-id) [above = of pgroup] {Bezeichnung} edge (pgroup);
\node[attribute] (group-id) [right = of pgroup] {\key{ANR}} edge (pgroup);
\end{tikzpicture}
\end{adjustbox}
\end{document}
結果如下:
在 Word 的樣子如下:
那麼如何在ER圖中加入空盒子和空氣泡呢?我非常感謝你的幫忙!
答案1
這是第二個版本,使用\TextField[options}{}
from package hyperref
。
更多配置請參見章。其手冊中有 9,例如變更邊框顏色。 (您可能還想設定inner sep=0pt
這些標註節點。)
現在,您的學生可以輸入答案、儲存 pdf 並將其發送給您。你可以閱讀它,或以一種或另一種方式提取他們的答案。
變化:
\usepackage{hyperref}
- 在這兩個節點中新增了單行和多行 TextField:
...
% ~~~ callouts ~~~~~~~~~~~~~~~~~~~
\node[ca,callout absolute pointer={(stud-id.330)}]
at ([shift=(-50:15mm)]stud-id) {\TextField[name=q1]{}};
\node[ca,callout absolute pointer={(name.west)},anchor=east,fill=teal!20]
at ([shift=(180:15mm)]name) {\TextField[name=q2, width=22mm, height=10mm, multiline=true]{}};
...
在檢視器(此處為 FireFox)中,輸入或查看答案:
%\documentclass[10pt,letterpaper]{article}
\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}
\usepackage{tikz-er2} % https://github.com/harrisony/tikz-er2/blob/usyd/tikz-er2.sty
%\usepackage{adjustbox}
\usetikzlibrary{shadows,positioning}
\usetikzlibrary{shapes.callouts}
\usepackage{hyperref}
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
\tikzset{
every entity/.style = { top color=white,bottom color=blue!30,
draw=blue!50!black!100,drop shadow},
every attribute/.style = { top color=white, bottom color=yellow!20,
draw=yellow, drop shadow},
every relationship/.style = { top color=white, bottom color=red!20,
draw=red!50!black!100, drop shadow},
every edge/.style = {link},
every isa/.style = { top color=white, bottom color=green!20,
draw=green!50!black!100, drop shadow},
}
%\begin{adjustbox}{width=\columnwidth,center}
\begin{tikzpicture}[
node distance=8em,
ca/.style={draw,rectangle callout,minimum width=3cm,minimum height=10mm},
]
% ~~~ ER-diagram ~~~~~~~~~~~~~~~~~~~~~~~~~~
\node[entity] (student) {Kunde};
\node[attribute] (stud-id) [left = of student]{\key{KNR}} edge (student);
\node[attribute] (name) [above = of student]{Name} edge (student);
\node[relationship] (joins) [right = of student]{kauft} edge (student);
\node[entity] (pgroup) [right = of joins] {Artikel} edge (joins);
\node[attribute] (group-id) [above = of pgroup] {Bezeichnung} edge (pgroup);
\node[attribute] (group-id) [right = of pgroup] {\key{ANR}} edge (pgroup);
% ~~~ callouts ~~~~~~~~~~~~~~~~~~~
\node[ca,callout absolute pointer={(stud-id.330)}]
at ([shift=(-50:15mm)]stud-id) {\TextField[name=q1]{}};
\node[ca,callout absolute pointer={(name.west)},anchor=east,fill=teal!20]
at ([shift=(180:15mm)]name) {\TextField[name=q2, width=22mm, height=10mm, multiline=true]{}};
\node[ca,callout absolute pointer={(joins.south)},anchor=north,dashed,draw=purple]
at ([yshift=-20mm, xshift=5mm)]joins) {};
\end{tikzpicture}
%\end{adjustbox}
\end{document}
答案2
這是一種方法,一次即可tikz-er2.sty
下載到文件目錄中,即可從github。
一些備註:
- 我事先減少了代碼噪音;-)
- 使用該
shapes.callouts
庫(並在 pgf 手冊中查找) {}
使用標註相關樣式定位具有空文字的節點- 我使用絕對指針,重新使用節點名稱(我找到的節點名稱)並以一種或另一種方式移動標註
- 節點樣式的重構可以而且應該繼續,例如用一些替換
\newcommand
- 在這裡,我只是將自己限制在一些可讀的程式碼中,重複類似的樣式模式
- 與往常一樣
Tikz
,樣式可以在本地覆蓋,請參閱teal
和dashed
- 對於開發繪圖,我更喜歡課堂
standalone
;根據需要(取消)註釋或透過套件遵循路徑graphicx
,透過此查詢查找範例
%\documentclass[10pt,letterpaper]{article}
\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage[lmargin=1in,rmargin=1in,tmargin=1in,bmargin=1in]{geometry}
\usepackage{tikz-er2} % https://github.com/harrisony/tikz-er2/blob/usyd/tikz-er2.sty
%\usepackage{adjustbox}
\usetikzlibrary{shadows,positioning}
\usetikzlibrary{shapes.callouts}
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}
\tikzset{
every entity/.style = { top color=white,bottom color=blue!30,
draw=blue!50!black!100,drop shadow},
every attribute/.style = { top color=white, bottom color=yellow!20,
draw=yellow, drop shadow},
every relationship/.style = { top color=white, bottom color=red!20,
draw=red!50!black!100, drop shadow},
every edge/.style = {link},
every isa/.style = { top color=white, bottom color=green!20,
draw=green!50!black!100, drop shadow},
}
%\begin{adjustbox}{width=\columnwidth,center}
\begin{tikzpicture}[
node distance=8em,
ca/.style={draw,rectangle callout,minimum width=3cm,minimum height=10mm},
]
% ~~~ ER-diagram ~~~~~~~~~~~~~~~~~~~~~~~~~~
\node[entity] (student) {Kunde};
\node[attribute] (stud-id) [left = of student]{\key{KNR}} edge (student);
\node[attribute] (name) [above = of student]{Name} edge (student);
\node[relationship] (joins) [right = of student]{kauft} edge (student);
\node[entity] (pgroup) [right = of joins] {Artikel} edge (joins);
\node[attribute] (group-id) [above = of pgroup] {Bezeichnung} edge (pgroup);
\node[attribute] (group-id) [right = of pgroup] {\key{ANR}} edge (pgroup);
% ~~~ callouts ~~~~~~~~~~~~~~~~~~~
\node[ca,callout absolute pointer={(stud-id.330)}]
at ([shift=(-50:15mm)]stud-id) {};
\node[ca,callout absolute pointer={(name.west)},anchor=east,fill=teal!20]
at ([shift=(180:15mm)]name) {};
\node[ca,callout absolute pointer={(joins.south)},anchor=north,dashed,draw=purple]
at ([yshift=-20mm, xshift=5mm)]joins) {};
\end{tikzpicture}
%\end{adjustbox}
\end{document}