코드를 조정했습니다이 게시물에서
내가 겪고 있는 문제는 테이블 사이의 관계(선)가 테이블을 둘러싸는 것이 아니라 테이블을 가로질러 가고 있다는 것입니다.
MWE는 꽤 길지만 여기에는 다음과 같은 내용이 있습니다.
\documentclass[border=0.25in]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows}
\usetikzlibrary{calc}
\makeatletter
\pgfarrowsdeclare{crow's foot}{crow's foot}
{
\pgfarrowsleftextend{+-.5\pgflinewidth}%
\pgfarrowsrightextend{+.5\pgflinewidth}%
}
{
\pgfutil@tempdima=0.5pt%
\advance\pgfutil@tempdima by.25\pgflinewidth%
\pgfsetdash{}{+0pt}%
\pgfsetmiterjoin%
\pgfpathmoveto{\pgfqpoint{0pt}{-6\pgfutil@tempdima}}%
\pgfpathlineto{\pgfqpoint{-6\pgfutil@tempdima}{0pt}}%
\pgfpathlineto{\pgfqpoint{0pt}{6\pgfutil@tempdima}}%
\pgfusepathqstroke%
}
\tikzset{
entity/.code={
\tikzset{
label=above:#1,
name=#1,
inner sep=0pt,
every entity/.try,
fill=white,
general shadow={
shadow xshift=0.0625in,
shadow yshift=-0.0625in,
opacity=0.5,
fill=black!50
}
}%
\def\entityname{#1}%
},
entity anchor/.style={matrix anchor=#1.center},
every entity/.style={
draw,
},
every property/.style={
inner xsep=0.25cm, inner ysep=0.125cm, anchor=west, text width=1.5in
},
zig zag to/.style={
to path={(\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget)}
},
zig zag to/.default=0.5,
one to many/.style={
-crow's foot, zig zag to
},
many to one/.style={
crow's foot-, zig zag to
},
many to many/.style={
crow's foot-crow's foot, zig zag to
}
}
\def\property#1{\node[name=\entityname-#1, every property/.try]{#1};}
\def\properties{\begingroup\catcode`\_=11\relax\processproperties}
\def\processproperties#1{\endgroup%
\def\propertycode{}%
\foreach \p in {#1}{%
\expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter\propertycode%
\expandafter\expandafter\expandafter{\expandafter\propertycode\expandafter\property\expandafter{\p}\\}%
}%
\propertycode%
}
\begin{document}
\begin{tikzpicture}[every node/.style={font=\ttfamily}, node distance=1.25in]
\matrix [entity=Order Form, entity anchor=Order Form-Order ID -> PK] {
\properties{
Order ID -> PK,
Cust ID -> FK,
Order Date
}
};
\matrix [entity=Product Table, right=of Order Form-Order ID -> PK, entity anchor=Product Table-Vinyl ID -> PK] {
\properties{
Vinyl ID -> PK,
title,
release year,
record lbl,
artist,
album / single,
cost price,
Supplier ID -> FK,
Retail Price,
Reorder Lvl,
Stock Lvl
}
};
\matrix [entity=Supplier Table, below=of Product Table, entity anchor=Supplier Table-Supplier ID -> PK] {
\properties{
Supplier ID -> PK,
Supplier Name,
Sup Add 1,
Sup Add 2,
Sup Add 3
}
};
\matrix [entity=Order Details, left=of Supplier Table, entity anchor=Order Details-Vinyl ID -> FK] {
\properties{
Vinyl ID -> FK,
Order ID -> FK,
Quantity
}
};
\matrix [entity=Customer Table, below=of Supplier Table, entity anchor=Customer Table-Cust ID] {
\properties{
Cust ID,
First Name,
Surname,
Email,
Postcode,
Add. Line 1,
Add. Line 2,
Add. Line 3
}
};
\draw [one to many] (Product Table-Vinyl ID -> PK) to (Order Details-Vinyl ID -> FK);
\draw [one to many] (Order Form-Order ID -> PK) to (Order Details-Order ID -> FK);
\draw [one to many] (Customer Table-Cust ID) to (Order Form-Cust ID -> FK);
\draw [one to many] (Supplier Table-Supplier ID -> PK) to (Product Table-Supplier ID -> FK);
\end{tikzpicture}
\end{document}
다음은 문제의 이미지입니다(즉각적으로 더 명확해질 수 있음).
현재와 같은 방식으로 상자 위로 선이 넘어가는 것을 어떻게 막을 수 있는지 잘 모르겠습니다. 이 동작을 방지하는 변경 값을 찾을 수 없습니다.
한편, 이 작업을 수행하는 것은 상당히 노동 집약적인 것처럼 보입니다. 다른 방법에 대한 다른 사람의 제안이 있으면 기꺼이 듣고 싶습니다.
감사합니다
답변1
이것이 가능한 해결책 중 하나입니다. 스타일 zig zag to
은 기본값 0.5로 설정됩니다.
zig zag to/.default=0.5
또한 one to many
다음 두 스타일도 오류를 일으키는 기본값을 사용합니다. 이 제안은 스타일 정의 zig zag to
에서 를 제거하므로 one to many
사용하지 않습니다.
\draw (<start>) to (<end>)
명령 의 구문 draw
. 그러나 오히려 상대적이고 직교적인 좌표 그리기 기술을 자주 사용하는 것을 사용하십시오.
\draw (<start>) --++(x,0) |- (<end>);
내부 레이블이 여전히 유효 (<start>)
하고 (<end>)
로컬 좌표를 포함하고 있기 때문입니다.
암호
\documentclass[border=0.25in]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows}
\usetikzlibrary{calc}
\makeatletter
\pgfarrowsdeclare{crow's foot}{crow's foot}
{
\pgfarrowsleftextend{+-.5\pgflinewidth}%
\pgfarrowsrightextend{+.5\pgflinewidth}%
}
{
\pgfutil@tempdima=0.5pt%
\advance\pgfutil@tempdima by.25\pgflinewidth%
\pgfsetdash{}{+0pt}%
\pgfsetmiterjoin%
\pgfpathmoveto{\pgfqpoint{0pt}{-6\pgfutil@tempdima}}%
\pgfpathlineto{\pgfqpoint{-6\pgfutil@tempdima}{0pt}}%
\pgfpathlineto{\pgfqpoint{0pt}{6\pgfutil@tempdima}}%
\pgfusepathqstroke%
}
\makeatother
\tikzset{
entity/.code={
\tikzset{
label=above:#1,
name=#1,
inner sep=0pt,
every entity/.try,
fill=white,
general shadow={
shadow xshift=0.0625in,
shadow yshift=-0.0625in,
opacity=0.5,
fill=black!50
}
}%
\def\entityname{#1}%
},
entity anchor/.style={matrix anchor=#1.center},
every entity/.style={
draw,
},
every property/.style={
inner xsep=0.25cm, inner ysep=0.125cm, anchor=west, text width=1.5in
},
zig zag to/.style={
to path={(\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget)}
},
zig zag to/.default=0.5,
one to many/.style={
-crow's foot, % zig zag to % disable this `zig zag to` command by mark it out
},
many to one/.style={
crow's foot-, zig zag to
},
many to many/.style={
crow's foot-crow's foot, zig zag to
}
}
\def\property#1{\node[name=\entityname-#1, every property/.try]{#1};}
\def\properties{\begingroup\catcode`\_=11\relax\processproperties}
\def\processproperties#1{\endgroup%
\def\propertycode{}%
\foreach \p in {#1}{%
\expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter\propertycode%
\expandafter\expandafter\expandafter{\expandafter\propertycode\expandafter\property\expandafter{\p}\\}%
}%
\propertycode%
}
\begin{document}
\begin{tikzpicture}[every node/.style={font=\ttfamily}, node distance=1.25in]
\matrix [entity=Order Form, entity anchor=Order Form-Order ID -> PK] {
\properties{
Order ID -> PK,
Cust ID -> FK,
Order Date
}
};
\matrix [entity=Product Table, right=of Order Form-Order ID -> PK, entity anchor=Product Table-Vinyl ID -> PK] {
\properties{
Vinyl ID -> PK,
title,
release year,
record lbl,
artist,
album / single,
cost price,
Supplier ID -> FK,
Retail Price,
Reorder Lvl,
Stock Lvl
}
};
\matrix [entity=Supplier Table, below=of Product Table, entity anchor=Supplier Table-Supplier ID -> PK] {
\properties{
Supplier ID -> PK,
Supplier Name,
Sup Add 1,
Sup Add 2,
Sup Add 3
}
};
\matrix [entity=Order Details, left=of Supplier Table, entity anchor=Order Details-Vinyl ID -> FK] {
\properties{
Vinyl ID -> FK,
Order ID -> FK,
Quantity
}
};
\matrix [entity=Customer Table, below=of Supplier Table, entity anchor=Customer Table-Cust ID] {
\properties{
Cust ID,
First Name,
Surname,
Email,
Postcode,
Add. Line 1,
Add. Line 2,
Add. Line 3
}
};
\draw [one to many] (Product Table-Vinyl ID -> PK) --++(-2.7,0) |- (Order Details-Vinyl ID -> FK);
\draw [one to many] (Order Form-Order ID -> PK) --++(-3,0) |- (Order Details-Order ID -> FK);
\draw [one to many] (Customer Table-Cust ID) --++(-2.7,0) |-(Order Form-Cust ID -> FK);
\draw [one to many] (Product Table-Supplier ID -> FK) --++(3,0) |- (Supplier Table-Supplier ID -> PK) ;
\end{tikzpicture}
\end{document}
답변2
zig zag to
좌표 가 다른 점 사이에서만 잘 작동 합니다 x
.
예를 들어 zig zig to
동일한 점에 대해 잘 작동하는 다른 스타일을 정의 x
하고 이를 사용하여 새 스타일을 정의 할 수 있습니다 one to many bis
.
one to many
의 매개변수에 대한 액세스를 추가하여 변경했습니다 zig zag to
. 이런 식으로 가장자리가 겹치지 않습니다.
코드는 다음과 같습니다.
\documentclass[border=0.25in]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usetikzlibrary{shadows}
\usetikzlibrary{calc}
\makeatletter
\pgfarrowsdeclare{crow's foot}{crow's foot}
{
\pgfarrowsleftextend{+-.5\pgflinewidth}%
\pgfarrowsrightextend{+.5\pgflinewidth}%
}
{
\pgfutil@tempdima=0.5pt%
\advance\pgfutil@tempdima by.25\pgflinewidth%
\pgfsetdash{}{+0pt}%
\pgfsetmiterjoin%
\pgfpathmoveto{\pgfqpoint{0pt}{-6\pgfutil@tempdima}}%
\pgfpathlineto{\pgfqpoint{-6\pgfutil@tempdima}{0pt}}%
\pgfpathlineto{\pgfqpoint{0pt}{6\pgfutil@tempdima}}%
\pgfusepathqstroke%
}
\tikzset{
entity/.code={
\tikzset{
label=above:#1,
name=#1,
inner sep=0pt,
every entity/.try,
fill=white,
general shadow={
shadow xshift=0.0625in,
shadow yshift=-0.0625in,
opacity=0.5,
fill=black!50
}
}%
\def\entityname{#1}%
},
entity anchor/.style={matrix anchor=#1.center},
every entity/.style={
draw,
},
every property/.style={
inner xsep=0.25cm, inner ysep=0.125cm, anchor=west, text width=1.5in
},
zig zag to/.style={
to path={(\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget)}
},
zig zag to/.default=0.5,
zig zig to/.style={
to path={(\tikztostart) -| ++(#1,0) |- (\tikztotarget)}
},
zig zig to/.default=2.5cm,
one to many/.style={
-crow's foot, zig zag to=#1
},
one to many bis/.style={
-crow's foot, zig zig to=#1
},
many to one/.style={
crow's foot-, zig zig to=#1
},
many to many/.style={
crow's foot-crow's foot, zig zag to=#1
}
}
\def\property#1{\node[name=\entityname-#1, every property/.try]{#1};}
\def\properties{\begingroup\catcode`\_=11\relax\processproperties}
\def\processproperties#1{\endgroup%
\def\propertycode{}%
\foreach \p in {#1}{%
\expandafter\expandafter\expandafter\gdef\expandafter\expandafter\expandafter\propertycode%
\expandafter\expandafter\expandafter{\expandafter\propertycode\expandafter\property\expandafter{\p}\\}%
}%
\propertycode%
}
\begin{document}
\begin{tikzpicture}[every node/.style={font=\ttfamily}, node distance=1.25in]
\matrix [entity=Order Form, entity anchor=Order Form-Order ID -> PK] {
\properties{
Order ID -> PK,
Cust ID -> FK,
Order Date
}
};
\matrix [entity=Product Table, right=of Order Form-Order ID -> PK, entity anchor=Product Table-Vinyl ID -> PK] {
\properties{
Vinyl ID -> PK,
title,
release year,
record lbl,
artist,
album / single,
cost price,
Supplier ID -> FK,
Retail Price,
Reorder Lvl,
Stock Lvl
}
};
\matrix [entity=Supplier Table, below=of Product Table, entity anchor=Supplier Table-Supplier ID -> PK] {
\properties{
Supplier ID -> PK,
Supplier Name,
Sup Add 1,
Sup Add 2,
Sup Add 3
}
};
\matrix [entity=Order Details, left=of Supplier Table, entity anchor=Order Details-Vinyl ID -> FK] {
\properties{
Vinyl ID -> FK,
Order ID -> FK,
Quantity
}
};
\matrix [entity=Customer Table, below=of Supplier Table, entity anchor=Customer Table-Cust ID] {
\properties{
Cust ID,
First Name,
Surname,
Email,
Postcode,
Add. Line 1,
Add. Line 2,
Add. Line 3
}
};
\draw [one to many=.45 ] (Product Table-Vinyl ID -> PK) to (Order Details-Vinyl ID -> FK);
\draw [one to many bis=-3cm] (Order Form-Order ID -> PK) to (Order Details-Order ID -> FK);
\draw [one to many] (Customer Table-Cust ID) to (Order Form-Cust ID -> FK);
\draw [one to many bis=3cm] (Supplier Table-Supplier ID -> PK) to (Product Table-Supplier ID -> FK);
\end{tikzpicture}
\end{document}