3

I am in the process of creating a worksheet for my students. It's about ER-diagrams. It's relatively easy with Word, but it doesn't look so nice ;)

I already know how to create ER-diagrams. What I would like to have are fields that the students have to fill out. Here my code:

\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}

Here is the result:

enter image description here

And here what it looks like in Word:

enter image description here

So how to add empty boxes and empty speech bubbles to the ER diagram? I'm very thankful for your help!

4
  • Do you want them to write on paper, or electronically in a pdf? How important is the empty fields shape?
    – MS-SPO
    Apr 15 at 16:06
  • @MS-SPO The shapes are not so important. Is it possible for them to do this electronically? I would be interested in both, if you ask :)
    – wayne
    Apr 15 at 16:09
  • 1
    It‘s possible, search the web for: ctan hyperref
    – MS-SPO
    Apr 15 at 16:11
  • @MS-SPO Great thank you. But do you have a solution to my original problem?
    – wayne
    Apr 15 at 16:15

2 Answers 2

3

Here's the second version, using \TextField[options}{} from package hyperref.

For further configurations see Ch. 9 in its manual, e.g. to change border colors. (You may also want to set inner sep=0pt for those callout nodes.)

Now your students can enter answers, save the pdf and send it to you. You can either read it, or, one way or the other, extract their answers.

Changes:

  • \usepackage{hyperref}
  • added a single line and a multiline TextField in these two nodes:
...
    % ~~~ 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]{}};
...

In a viewer, here FireFox, enter or review answers:

result

%\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}
4

Here's a way to do it, once tikz-er2.sty is downloaded e.g. into the documents directory, from github.

Some remarks:

  • I reduced code-noise beforehand ;-)
  • use the shapes.callouts library (and look it up in the pgfmanual)
  • position nodes with empty text {} using callouts-related styles
  • I used absolute pointers, re-using your node names (those I found) AND shift the callout one way or the other
  • refactoring of node-styles could and should be continuied, e.g. be replaceing with some \newcommand
  • here I just restricted myself to a somewhat readable code, repeating similar style patterns
  • as usual with Tikz, styles can be overwritten locally, see teal and dashed
  • for developing drawings I prefer class standalone; (un)comment as needed OR follow the path via package graphicx, find examples via this query

result

%\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .