我正在记录不同版本的数据库绘图样式。
此链接显示了它在实际图表中的样子,但我的意图是仅记录连接线的一侧。现在,示例非常完美地展示了如何绘制,它是通过链接一些 PGF 和 TikZ 代码来完成的,但我无法将其重新设计为以 Crow's Foot 设计线端结尾的单线。就像 1:1 连接是这样的:-||---
它总是显示另一端,就像它在 1:1-1:1 图表中使用一样,就像这样-||------||-
。
也许有人可以告诉我如何更改 PGF 代码来获得单个鱼尾纹?这是我的 MWE:
\documentclass{article}%
\usepackage{tikz}
\usetikzlibrary{%
chains,
}
\tikzset{
dummy/.style={
rectangle,
rounded corners,
draw=white, very thick,
text centered},
zig zag to/.style={
to path={(\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget) \tikztonodes}
},
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
},
}
\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%
}
\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%
}
\def\pk#1{\node[name=\entityname-#1, every property/.try]{#1};
\node[name=\entityname-#1, every property/.try, red, text width=1in, align=right,]{(PK)};
\\}
\def\fk#1{\node[name=\entityname-#1, every property/.try]{#1};
\node[name=\entityname-#1, every property/.try, red, text width=1in, align=right]{(FK)};
\\}
\begin{document}
\section{Notation Versions}
\begin{tabular}{lllll}
NOTATION & ==1 & 0 to 1 & 1 to n & n to n \\[1em]
IEM & & & & \\[1em]
CHEN & 1:1 & 0:1 & 1:n & 0:n \\[1em]
\end{tabular}\\[5em]
\scalebox{0.4}{
\begin{tikzpicture}
\node[dummy, inner sep=5pt] (a) {};
\node[dummy, inner sep=5pt,right=2cm of a] (b) {};
\draw[one to one] (a.east) -- node[above]{} (b.west);
\end{tikzpicture}
}
\scalebox{0.4}{
\begin{tikzpicture}
\node[dummy, inner sep=5pt] (a) {};
\node[dummy, inner sep=5pt,right=2cm of a] (b) {};
\draw[one to many] (a.east) -- node[above]{} (b.west);
\end{tikzpicture}
}
\scalebox{0.4}{
\begin{tikzpicture}
\node[dummy, inner sep=5pt] (a) {};
\node[dummy, inner sep=5pt,right=2cm of a] (b) {};
\draw[one to omany] (a.east) -- node[above]{} (b.west);
\end{tikzpicture}
}
\scalebox{0.4}{
\begin{tikzpicture}
\node[dummy, inner sep=5pt] (a) {};
\node[dummy, inner sep=5pt,right=2cm of a] (b) {};
\draw[many to one] (a.east) -- node[above]{} (b.west);
\end{tikzpicture}
}
\scalebox{0.4}{
\begin{tikzpicture}
\node[dummy, inner sep=5pt] (a) {};
\node[dummy, inner sep=5pt,right=2cm of a] (b) {};
\draw[many to many] (a.east) -- node[above]{} (b.west);
\end{tikzpicture}
}
\end{document}
获得这部分内容作为一方面之后,我有一个关于使用 PGF 绘制鱼尾纹线条的附加问题。
我需要添加一个尚未实现的线端。它被称为 0 到 1,如下所示:我试图理解鱼尾纹是如何绘制的,但我不明白它来自哪里。有人能给我展示一下绘制/编码鱼尾纹三个脚趾的代码吗?也许这样我就可以得到“one”=和“omany”=-|O---
的混合 -||---
/|\O---
对于任何想要在未来做同样事情的人来说,这是本次讨论的最终结果:
\documentclass{article} % say
\usepackage{tikz}
\usetikzlibrary{%
chains,
}
\tikzset{
dummy/.style={
rectangle,
rounded corners,
draw=white, very thick,
text centered},
zig zag to/.style={ %this is the connection of lines and nodes
to path={(\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget) \tikztonodes}
},
zig zag to/.default=0.5,
one to one/.style={
one-one, zig zag to
},
none to one/.style={
one-, zig zag to
},
none to oone/.style={
oone-, zig zag to
},
one to many/.style={
one-crow's foot, zig zag to,
},
none to many/.style={
crow's foot-, zig zag to,
},
one to omany/.style={
one-omany, zig zag to
},
none to omany/.style={
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
},
}
\makeatletter
\pgfarrowsdeclare{crow's foot}{crow's foot} %this is many
{
\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} %this is 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} %this is 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%
}
\pgfarrowsdeclare{oone}{oone}
{
\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}}%
\pgfpathcircle{\pgfpoint{-11.5pt}{0}} {3.5pt}
\pgfusepathqstroke%
}
\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}
\section{Notation Versions}
\begin{tabular}{lllll}
NOTATION & ==1 & 0 to 1 & 1 to n & 0 to m \\[1em]%zeile 1
IEM / crow's foot%
& % == 1
\scalebox{0.5}{
\begin{tikzpicture}
\node[dummy, inner sep=5pt] (a) {};
\node[dummy, inner sep=5pt,right=1cm of a] (b) {};
\draw[none to one] (a.east) -- node[above]{} (b.west);
\end{tikzpicture}
} & % 0 to 1
\scalebox{0.5}{
\begin{tikzpicture}
\node[dummy, inner sep=5pt] (a) {};
\node[dummy, inner sep=5pt,right=1cm of a] (b) {};
\draw[none to oone] (a.east) -- node[above]{} (b.west);
\end{tikzpicture}
} & % 1 to n
\scalebox{0.5}{
\begin{tikzpicture}
\node[dummy, inner sep=5pt] (a) {};
\node[dummy, inner sep=5pt,right=1cm of a] (b) {};
\draw[none to many] (a.east) -- node[above]{} (b.west);
\end{tikzpicture}
} & % n to m
\scalebox{0.5}{
\begin{tikzpicture}
\node[dummy, inner sep=5pt] (a) {};
\node[dummy, inner sep=5pt,right=1cm of a] (b) {};
\draw[none to omany] (a.east) -- node[above]{} (b.west);
\end{tikzpicture}
}\\[1em]%zeile 2
CHEN & 1:1 & 0:1 & 1:n & 0:n \\[1em]%zeile 3
\end{tabular}\\[2em]
\end{document}
答案1
看看one to none
下面 MWE 中的风格。
编辑:为了回答附加问题,我添加了omany to none
和oone to none
。
编辑2:添加many to one
并重新设计。
\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\renewcommand{\arraystretch}{1.4}
\usepackage{tikz}
\tikzset{
zig zag to/.style={
to path={(\tikztostart) -| ($(\tikztostart)!#1!(\tikztotarget)$) |- (\tikztotarget) \tikztonodes}
},
zig zag to/.default=0.5,
one to one/.style={
one-one, zig zag to
},
one to none/.style={
one-, zig zag to
},
oone to none/.style={
oone-, zig zag to
},
omany to none/.style={
omany-, 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
},
many to none/.style={
crow's foot-, zig zag to
},
}
\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{oone}{oone}
{
\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}}%
\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%
}
\begin{document}
\section{Notation Versions}
\begin{tabular}{lcc}
\toprule
Notation & IEM & CHEN \\
\midrule
one to none &
\tikz{\draw[one to none] (0,0) -- ++(1.5,0);} & 1:0\\
one to one & \tikz{\draw[one to one] (0,0) -- ++(1.5,0);} & 1:1\\
one to many & \tikz{\draw[one to many] (0,0) -- ++(1.5,0);} & 1:n\\
many to none & \tikz{\draw[many to none] (0,0) -- ++(1.5,0);} & n:0\\
one to (none or one or many) &\tikz{\draw[one to omany] (0,0) -- ++(1.5,0);} & \\
many to one & \tikz{\draw[many to one] (0,0) -- ++(1.5,0);} & n:1\\
many to many &\tikz{\draw[many to many] (0,0) -- ++(1.5,0);} & n:m\\
(none or one or many) to none &\tikz{\draw[omany to none] (0,0) -- ++(1.5,0);} & \\
(none or one) to none &\tikz{\draw[oone to none] (0,0) -- ++(1.5,0);} & \\
\bottomrule
\end{tabular}
\end{document}