我正在为我的学生创建一份工作表。它是关于 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}{}
来自包的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
库(并在 pgfmanual 中查找) {}
使用与标注相关的样式来定位具有空文本的节点- 我使用了绝对指针,重复使用你的节点名称(我找到的那些)并以某种方式移动标注
- 节点样式的重构可以而且应该继续,例如用一些替换
\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}