Crow's Foot ERM은 좋은 방법입니다.

Crow's Foot ERM은 좋은 방법입니다.

나는 찾았다이것Tikz를 사용하여 Crow's Foot ERM 다이어그램을 수행하는 방법에 대한 게시물이 있지만 엔터티가 프레임 외부에 있기 때문에 이상해 보입니다. 그러나 그것은 효과가 있었습니다.

그러다가 찾았어요이것더 좋은 버전을 만들어 결합하려고 시도했지만 안타깝게도 왜 작동하지 않는지 알 수 없습니다. 두 엔터티를 나란히 인쇄하여 까마귀 발 와이어로 연결할 수 없습니다. 그들은 항상 서로 겹쳐서 인쇄합니다 ...

어떻게 선과 스타일을 모두 가질 수 있나요?

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows}
\usetikzlibrary{calc}

\tikzset{
    entity/.code={
        \tikzset{
            rounded corners,             
            name=#1,
            inner sep=2pt,
            every entity/.try,
        }%
        \def\entityname{#1}%
    },
    entity anchor/.style={matrix anchor=#1},
    every entity/.style={
            draw,
    },
    every property/.style={
        inner xsep=0.20cm, inner ysep=0.075cm, anchor=west, text width=1.75in
    }
}
\def\property#1{\node[name=\entityname-#1, every property/.try]{\propertysplit#1;};}
\def\properties{\begingroup\catcode`\_=11\relax\processproperties}
\def\processproperties#1{\endgroup%
    \gdef\propertycode{}%
    \foreach \p in {#1}{%
    \expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter\propertycode%
            \expandafter\expandafter\expandafter{\expandafter\propertycode\expandafter\property\expandafter{\p}\\}%
    }%
    \propertycode%
}
\def\propertysplit#1:#2;{#1:\hfill#2}

\def\entitynamenode{%
\node[every entity name/.try] (\entityname-name) {\entityname};
\draw (\entityname-name.south west) -- (\entityname-name.south east);
\\[1ex]
}
\tikzset{
  every entity name/.style={every property/.try, align=center}
}
\begin{document}
\begin{tikzpicture}[every node/.style={font=\ttfamily}, node distance=0.5in]
\matrix (m1) [entity=Employee] {
    \entitynamenode
    \properties{
        Username:,
        Password :  varchar(255),        
        Name :  varchar(255),
        LastName :  varchar(255)
    }
};
\matrix (m2) [entity=Student] {
    \entitynamenode
    \properties{
        Username:,
        Password :  varchar(255),        
        Name :  varchar(255),
        LastName :  varchar(255)
    }
};
\draw [->] (m1) -- (m2); % <-- it break's here...
%\draw [one to omany] (Employee-Username:) to node[above]{label} (Student-Username:);
\end{tikzpicture}
\end{document} 

여기에 이미지 설명을 입력하세요

편집: 이것은 IT 데이터베이스 구조를 시각화하기 위한 까마귀 발 표기법입니다.

IT 데이터베이스 구조 시각화를 위한 까마귀 발 표기법

답변1

귀하의 MWE는 내 지식 수준보다 높으므로 내부가 포함된 pic( entity) 솔루션을 제안합니다 tabular.

의 인수는 pic3개입니다: 노드 이름, 엔터티 이름 및 행 tabular(아마도 세 번째 인수로 전체를 갖는 것이 더 우아할 수 있습니다 tabular. 이 경우 피하기 위해 두 개의 새로운 열 유형을 정의할 수 있습니다) 항상 입력하세요).

등 의 코드는 one to many다음에서 가져옵니다.당신이 링크한 게시물 중 하나.

엔터티의 크기가 tabular.

\documentclass{article}
\usepackage{array}
\renewcommand{\arraystretch}{1.1}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows}
\usetikzlibrary{calc}

% code for "one to omany", etc. is taken from https://tex.stackexchange.com/q/141797/101651
\makeatletter
\pgfarrowsdeclare{crow's foot}{crow's foot}
{
    \pgfarrowsleftextend{+-.5\pgflinewidth}%
    \pgfarrowsrightextend{+.5\pgflinewidth}%
}
{
    \pgfutil@tempdima=0.6pt%
    %\advance\pgfutil@tempdima by.25\pgflinewidth%
    \pgfsetdash{}{+0pt}%
    \pgfsetmiterjoin%
    \pgfpathmoveto{\pgfqpoint{0pt}{-9\pgfutil@tempdima}}%
    \pgfpathlineto{\pgfqpoint{-13\pgfutil@tempdima}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{9\pgfutil@tempdima}}%
    \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}%
    \pgfpathmoveto{\pgfqpoint{-8pt}{-6pt}}% 
    \pgfpathlineto{\pgfqpoint{-8pt}{-6pt}}%  
    \pgfpathlineto{\pgfqpoint{-8pt}{6pt}}% 
    \pgfusepathqstroke%
}

\pgfarrowsdeclare{omany}{omany}
{
    \pgfarrowsleftextend{+-.5\pgflinewidth}%
    \pgfarrowsrightextend{+.5\pgflinewidth}%
}
{
    \pgfutil@tempdima=0.6pt%
    %\advance\pgfutil@tempdima by.25\pgflinewidth%
    \pgfsetdash{}{+0pt}%
    \pgfsetmiterjoin%
    \pgfpathmoveto{\pgfqpoint{0pt}{-9\pgfutil@tempdima}}%
    \pgfpathlineto{\pgfqpoint{-13\pgfutil@tempdima}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{9\pgfutil@tempdima}}%
    \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}%  
    \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}%
    \pgfpathmoveto{\pgfqpoint{-6pt}{-6pt}}% 
    \pgfpathcircle{\pgfpoint{-11.5pt}{0}} {3.5pt}
    \pgfusepathqstroke%
}

\pgfarrowsdeclare{one}{one}
{
    \pgfarrowsleftextend{+-.5\pgflinewidth}%
    \pgfarrowsrightextend{+.5\pgflinewidth}%
}
{
    \pgfutil@tempdima=0.6pt%
    %\advance\pgfutil@tempdima by.25\pgflinewidth%
    \pgfsetdash{}{+0pt}%
    \pgfsetmiterjoin%
    \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}%
    \pgfpathmoveto{\pgfqpoint{-6pt}{-6pt}}% 
    \pgfpathlineto{\pgfqpoint{-6pt}{-6pt}}%  
    \pgfpathlineto{\pgfqpoint{-6pt}{6pt}}% 
    \pgfpathmoveto{\pgfqpoint{0\pgfutil@tempdima}{0\pgfutil@tempdima}}%
    \pgfpathmoveto{\pgfqpoint{-8pt}{-6pt}}% 
    \pgfpathlineto{\pgfqpoint{-8pt}{-6pt}}%  
    \pgfpathlineto{\pgfqpoint{-8pt}{6pt}}%    
    \pgfusepathqstroke%
}
\makeatother

\tikzset{%
    pics/entity/.style n args={3}{code={%
            \node[draw, blue,
            shade, top color=white, bottom color=blue!30,
            drop shadow={gray!70,
                shadow xshift=3pt,
                shadow yshift=-3pt,
                rounded corners},  
            rounded corners,  
            font=\ttfamily\footnotesize, 
            rectangle
            ] (#1)
            {\color{black}\begin{tabular}{>{\raggedright\arraybackslash}p{4.5em}>{\raggedleft\arraybackslash}p{6em}}
                    #3
                \end{tabular}
            };%
            \node[font=\ttfamily\footnotesize,
            text height=1.5ex,text depth=.25ex,
            above =0pt of #1
            ] 
            {#2};%
    }},
    pics/entitysimple/.style n args={3}{code={%
            \node[draw, rounded corners,             
            rectangle split,
            rectangle split parts=2,
            font=\ttfamily\footnotesize,
            text height=1.5ex,text depth=.25ex
            ] (#1)
            {#2 \nodepart{second} 
                \begin{tabular}{>{\raggedright\arraybackslash}p{4.5em}>{\raggedleft\arraybackslash}p{6em}}
                    #3
                \end{tabular}
            };%
    }},
    zig zag to/.style={
        to path={(\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget)}
    },
    zig zag to/.default=0.5,   
    one to one/.style={
        one-one, zig zag to
    },    
    one to many/.style={
        one-crow's foot, zig zag to,
    },
    one to omany/.style={
        one-omany, zig zag to
    },      
    many to one/.style={
        crow's foot-one, zig zag to
    },
    many to many/.style={
        crow's foot-crow's foot, zig zag to
    }, 
}
\begin{document}
    \noindent Version like your colored image:
    \begin{center}
        \begin{tikzpicture}
        \pic {entity={empl}{Employee}{%
                Username: & \textcolor{red}{(PK)} \\
                Password: & varchar(255) \\        
                Name: & varchar(255) \\
                LastName: & varchar(255) \\ 
        }};
        \pic[right=7em of empl] {entity={stud}{Student}{%
                Username: & \textcolor{red}{(PK)} \\
                Password: & varchar(255) \\        
                Name: & varchar(255) \\
                LastName: & varchar(255) \\ 
        }};
        \pic[below=12ex of stud] {entity={thesis}{Thesis}{%
                Title: & \textcolor{red}{(PK)} \\
                Year: & numeric(4) \\        
        }};
        \draw[one to omany] ($(empl.north east)-(0,10pt)$) -- node[above]{\footnotesize\texttt{teaches}} ($(stud.north west)-(0,10pt)$);
        \draw[one to one] ($(stud.south)+(50pt,0)$) -- node[left]{\footnotesize\texttt{writes}} ($(thesis.north)+(50pt,0)$);
        \draw[one to many] ($(empl.south)+(30pt,0)$) |- node[left, yshift=36pt] {\footnotesize\texttt{supervises}} ($(thesis.west)+(0,4pt)$);
        \end{tikzpicture}
    \end{center}
    Version like your code:
    \begin{center}
        \begin{tikzpicture}
        \pic {entitysimple={empl}{Employee}{%
                Username: & \textcolor{red}{(PK)} \\
                Password: & varchar(255) \\        
                Name: & varchar(255) \\
                LastName: & varchar(255) \\ 
        }};
        \pic[right=7em of empl] {entitysimple={stud}{Student}{%
                Username: & \textcolor{red}{(PK)} \\
                Password: & varchar(255) \\        
                Name: & varchar(255) \\
                LastName: & varchar(255) \\ 
        }};
        \pic[below=12ex of stud] {entitysimple={thesis}{Thesis}{%
                Title: & \textcolor{red}{(PK)} \\
                Year: & numeric(4) \\        
        }};
        \draw[one to omany] (empl.east) -- node[above]{\footnotesize\texttt{teaches}} (stud.west);
        \draw[one to one] (stud.south) -- node[left]{\footnotesize\texttt{writes}} (thesis.north);
        \draw[one to many] (empl.south) |- node[left, yshift=44pt, xshift=-2pt] {\footnotesize\texttt{supervises}} (thesis.west);
        \end{tikzpicture}
    \end{center}        
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보