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 am drawing an ER-diagram and would like to show the relationships between tables.

enter image description here

I managed to create the tables:

\documentclass{article}
\usepackage[cm]{fullpage}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}

\tikzset{
  outernode/.style={draw,ultra thick,inner sep=0},
  innernode/.style={inner sep=.3333em,draw,rectangle split}
}
\newcommand\innernode[2]{\tikz\node[innernode,rectangle split parts=#1]{#2};}

\begin{document}
\begin{tikzpicture}
  \node (1) [outernode]
       { \innernode 2 {sco\_groups \nodepart{second} id} } ;
  \node (2) [below= 1cm of 1.south east, anchor=north west, outernode]
       { \innernode 3 {sco\_index \nodepart{second} tid \nodepart{third} sco\_id} } ;
\end{tikzpicture}
\end{document}

But don't know, how to create the line, uniting them (I marked it with red).

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Update:

I don't think using a \tikz \node (earlier solution -- below) is what you should be using. At least I could not figure out how to get access to particular nodepart with that method. So there are three updates here:

  • As per Jake's suggestions, it is easier to just simply use (1.south) |- (2.two west) to draw the line shown in red. Now to make a connection to the sco_id you can just access the side of this node via (2.three west).
  • The \innernode TeX macro has been eliminated.
  • The innernode style has been enhanced to accept an additional parameter to allow you to specify the number of inner nodes.

So, now you can easily access any nodepart you desire:

enter image description here


You can connect them via (1.south) -- ($(1.south |- 2.west)$) -- (2.west):

enter image description here


Code: Updated

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes, positioning}

\tikzset{
  outernode/.style={draw,ultra thick, inner sep=0},
  innernode/.style={inner sep=.3333em, draw, rectangle split, rectangle split parts=#1}
}

\begin{document}
\begin{tikzpicture}
    \node [outernode] (1)
        [innernode=2] { sco\_groups \nodepart{second} id} ;

    \node[below=1cm of 1.south east, anchor=north west, outernode] (2) 
        [innernode=3] {
            sco\_index 
            \nodepart{second} tid
            \nodepart{third} sco\_id
    };

    \draw [blue, ultra thick]  (1.-40)   |- (2.one west);
    \draw [red,  ultra thick]  
            (1.south)    node [below left, black] {$1$} |- 
            (2.two west) node [above left, black] {$n$};
    \draw [olive,   ultra thick]  (1.-140)   |- (2.three west);
\end{tikzpicture}
\end{document}

Code: Original

\documentclass{article}
\usepackage[cm]{fullpage}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}
\usetikzlibrary{calc}

\tikzset{
  outernode/.style={draw,ultra thick,inner sep=0},
  innernode/.style={inner sep=.3333em,draw,rectangle split}
}
\newcommand\innernode[2]{\tikz\node[innernode,rectangle split parts=#1]{#2};}

\begin{document}
\begin{tikzpicture}
  \node (1) [outernode]
       { \innernode 2 {sco\_groups \nodepart{second} id} } ;
  \node (2) [below= 1cm of 1.south east, anchor=north west, outernode]
       { \innernode 3 {sco\_index \nodepart{second} tid \nodepart{third} sco\_id} } ;

\draw [red, ultra thick] 
        (1.south) node [below left, black] {$1$} -- 
        ($(1.south |- 2.west)$) -- 
        (2.west) node [above left, black] {$n$};
\end{tikzpicture}
\end{document}
share|improve this answer
    
Could you, plz, add the code, joining id with sco_id? So I could join it with the bottom part of the split. –  user4035 Nov 27 '12 at 10:53
1  
@user4035 Change (2.west) to (2.three west) in the last \draw command. –  percusse Nov 27 '12 at 11:00
2  
@PeterGrill: Why not just use (1.south) |- (2.west)? –  Jake Nov 27 '12 at 11:02
    
@user4035: Have updated solution. Please let me know if the older solution has any value to you, otherwise I will remove that. –  Peter Grill Nov 27 '12 at 20:20
    
It has a great value. Plz, don't remove. –  user4035 Nov 27 '12 at 20:45

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.