Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have by looking at examples at this site got quite far with tikz but not all the way. I know this might be considered a bad question -- but since I got this far by looking at similar question this is probably the best we can do when it comes to tikz -- but here comes what I have now:

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}

\begin{document}
\begin{figure}
\begin{tikzpicture}

\matrix(Person) [matrix of nodes, 
                 matrix/.style={rows={1}{fill=gray}},
                 label=above:Person, 
                 column 1/.style={nodes={text width=1cm, align=center}},
                 column 2/.style={nodes={text width=2cm}},
                 column 3/.style={nodes={text width=2.5cm}},
                 column 4/.style={nodes={text width=2cm}},
                 column 5/.style={nodes={text width=2cm, align=center}}
                  ] {
    id & name       & address       & birth date & occupation.id \\
    1  & Mary Smith & Main street 1 & 1970-04-17 & 1 \\
    2  & John Doe   & Highway 2     & 1972-07-24 & 1 \\ 
    3  & Clara Doe  & Highway 2     & 1995-11-11 & 2 \\};

\matrix(Child) [matrix of nodes, 
                label=above:Child, 
                nodes={text width=2cm, align=center}, 
                right=1 cm of Person] {
    Person.id & Person.id \\ 
    2 & 3                 \\
                          \\};

\matrix(Occupation) [matrix of nodes, 
                     label=above:Occupation, 
                     below=1.25cm of Person,
                     nodes={text width=2.5cm},
                     column 1/.style={nodes={text width=1cm, align=center}}] {
    id & title     & location \\
    1  & secretary & Enterprises ltd \\
    2  & student   & School \\};

\draw[thick](Person-1-1.north west)--(Person-1-5.north east);
\draw(Person-1-1.south west)--(Person-1-5.south east);
\draw[thick](Person-4-1.south west)--(Person-4-5.south east);

\draw[thick](Child-1-1.north west)--(Child-1-2.north east);
\draw(Child-1-1.south west)--(Child-1-2.south east);
\draw[thick](Child-2-1.south west)--(Child-2-2.south east);

\draw[thick](Occupation-1-1.north west)--(Occupation-1-3.north east);
\draw(Occupation-1-1.south west)--(Occupation-1-3.south east);
\draw[thick](Occupation-3-1.south west)--(Occupation-3-3.south east);

\draw[<->] (Child-1-1.north)--++(0,1.5)-|(Person-1-1.north);
\draw[<->] (Child-1-2.north)--++(0,1.75)-|(Person-1-1.north);
\draw[<->] (Occupation-1-1.north)--++(0,1)-|(Person-4-5.south);
\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

I posted all of it cause it\s not that much and perhaps you while fixing what I can't fix also can show other better ways of doing what I have done -- both so I can learn and other people stumbling on this page also can learn.

Now, my problem is that I don't think it's clear enough what is table and what is not table. I think if the arrows didn't actually touch the table lines then perhaps it would become more clear. But I haven't so far managed to understand how to fix that...

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Some suggestions:

  1. To detach the arrows from the tables, you can use the shorten >= length , and shorten <= length keys.

  2. You can also change the line width and/or the color for the arrows. In my example code I used the help lines style.

  3. If you take a close look at your current tables, some of the lines are not completely horizontal due to different height and depth of the node contents; to guarantee equal dimensions (that will produce perfectly horizontal lines), you can set text depth and text height for the matrix nodes, or you could also use the perpendicular coordinate system to draw the lines. In my example I opted for the first option.

The code:

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}

\begin{document}
\begin{figure}
\begin{tikzpicture}

\matrix(Person) [matrix of nodes,
                 nodes={text depth=0.5ex,text height=2ex}, 
                 matrix/.style={rows={1}{fill=gray}},
                 label=above:Person, 
                 column 1/.style={nodes={text width=1cm, align=center}},
                 column 2/.style={nodes={text width=2cm}},
                 column 3/.style={nodes={text width=2.5cm}},
                 column 4/.style={nodes={text width=2cm}},
                 column 5/.style={nodes={text width=2cm, align=center}}
                  ] {
    id & name       & address       & birth date & occupation.id \\
    1  & Mary Smith & Main street 1 & 1970-04-17 & 1 \\
    2  & John Doe   & Highway 2     & 1972-07-24 & 1 \\ 
    3  & Clara Doe  & Highway 2     & 1995-11-11 & 2 \\};

\matrix(Child) [matrix of nodes, 
                label=above:Child, 
                nodes={text width=2cm, align=center}, 
                right=1 cm of Person] {
    Person.id & Person.id \\ 
    2 & 3                 \\
                          \\};

\matrix(Occupation) [matrix of nodes, 
                     label=above:Occupation, 
                     below=1.25cm of Person,
                     nodes={text width=2.5cm},
                     column 1/.style={nodes={text width=1cm, align=center}}] {
    id & title     & location \\
    1  & secretary & Enterprises ltd \\
    2  & student   & School \\};

\draw[thick](Person-1-1.north west)--(Person-1-5.north east);
\draw(Person-1-1.south west)--(Person-1-5.south east);
\draw[thick](Person-4-1.south west)--(Person-4-5.south east);

\draw[thick](Child-1-1.north west)--(Child-1-2.north east);
\draw(Child-1-1.south west)--(Child-1-2.south east);
\draw[thick](Child-2-1.south west)--(Child-2-2.south east);

\draw[thick](Occupation-1-1.north west)--(Occupation-1-3.north east);
\draw(Occupation-1-1.south west)--(Occupation-1-3.south east);
\draw[thick](Occupation-3-1.south west)--(Occupation-3-3.south east);

\begin{scope}[shorten >= 5pt,shorten <= 5pt,help lines,>=latex]
\draw[<->] (Child-1-1.north)--++(0,1.5)-|(Person-1-1.north);
\draw[<->] (Child-1-2.north)--++(0,1.75)-|(Person-1-1.north);
\draw[<->] (Occupation-1-1.north)--++(0,1)-|(Person-4-5.south);
\end{scope}

\end{tikzpicture}
\end{figure}

\end{document}

The result:

enter image description here

And adding rounded corners to the arrows might also improve the result:

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}

\begin{document}
\begin{figure}
\begin{tikzpicture}

\matrix(Person) [matrix of nodes,
                 nodes={text depth=0.5ex,text height=2ex}, 
                 matrix/.style={rows={1}{fill=gray}},
                 label=above:Person, 
                 column 1/.style={nodes={text width=1cm, align=center}},
                 column 2/.style={nodes={text width=2cm}},
                 column 3/.style={nodes={text width=2.5cm}},
                 column 4/.style={nodes={text width=2cm}},
                 column 5/.style={nodes={text width=2cm, align=center}}
                  ] {
    id & name       & address       & birth date & occupation.id \\
    1  & Mary Smith & Main street 1 & 1970-04-17 & 1 \\
    2  & John Doe   & Highway 2     & 1972-07-24 & 1 \\ 
    3  & Clara Doe  & Highway 2     & 1995-11-11 & 2 \\};

\matrix(Child) [matrix of nodes, 
                label=above:Child, 
                nodes={text width=2cm, align=center}, 
                right=1 cm of Person] {
    Person.id & Person.id \\ 
    2 & 3                 \\
                          \\};

\matrix(Occupation) [matrix of nodes, 
                     label=above:Occupation, 
                     below=1.25cm of Person,
                     nodes={text width=2.5cm},
                     column 1/.style={nodes={text width=1cm, align=center}}] {
    id & title     & location \\
    1  & secretary & Enterprises ltd \\
    2  & student   & School \\};

\draw[thick](Person-1-1.north west)--(Person-1-5.north east);
\draw(Person-1-1.south west)--(Person-1-5.south east);
\draw[thick](Person-4-1.south west)--(Person-4-5.south east);

\draw[thick](Child-1-1.north west)--(Child-1-2.north east);
\draw(Child-1-1.south west)--(Child-1-2.south east);
\draw[thick](Child-2-1.south west)--(Child-2-2.south east);

\draw[thick](Occupation-1-1.north west)--(Occupation-1-3.north east);
\draw(Occupation-1-1.south west)--(Occupation-1-3.south east);
\draw[thick](Occupation-3-1.south west)--(Occupation-3-3.south east);

\begin{scope}[shorten >= 5pt,shorten <= 5pt,help lines,>=latex,rounded corners]
\draw[<->] (Child-1-1.north)--++(0,1.5)-|(Person-1-1.north);
\draw[<->] (Child-1-2.north)--++(0,1.75)-|(Person-1-1.north);
\draw[<->] (Occupation-1-1.north)--++(0,1)-|(Person-4-5.south);
\end{scope}

\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.