我想创建具有任意传入/传出三角形组合的框,如下图所示:
我考虑过使用signal
TikZ 库中的shapes.symbols
,但signal
不支持框“一”的北面和南面的小传入和传出三角形。但是,它具有很好的传入/传出东/西三角形,如下所示:
来自也引起了我的注意,但它不支持传入三角形(如“三个”所示),仅支持传出的三角形arrow box
。shapes.arrows
我理想的解决方案是使用signal
传入/传出东/西三角形,并能够使用附加属性指定何时传入北/传出南三角形。例如(发明一些语法):
\node[signal to=east, innorth, outsouth] {one};
\node[signal from=west, signal to=east, innorth] {two};
\node[signal from=west] {three};
是否有可能具有这样的属性innorth
/ outsouth
? 或者还有其他获得此类盒子的好方法吗?
答案1
这是一个相当容易编码的提议,但它的缺点是它会用白色覆盖东西。如果你只想生成你描绘的节点,那就没问题了,但如果你把它们放在一些非平凡的背景之上,那就没问题了。
可以使用append after command
钩子在相应的边缘上放置一个开口三角形的图片。
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{shapes.symbols,positioning}
\begin{document}
\begin{tikzpicture}[nodes={minimum width=6em,minimum height=2em},
font=\sffamily,
pics/inlet/.style={code={\global\let\mytikzlastnode\tikzlastnode
\fill[white] (-1ex,\pgflinewidth) -- (-1ex,0) -- (0,-1ex) -- (1ex,0)
-- (1ex,\pgflinewidth);
\draw (-1.1ex,0) -- (-1ex,0) -- (0,-1ex) -- (1ex,0) -- (1.1ex,0);
}},innorth/.style={append after command={
([yshift=-\pgflinewidth/2]\tikzlastnode.north west) --
([yshift=-\pgflinewidth/2]\tikzlastnode.north east)
pic[midway,sloped]{inlet}
[/utils/exec=\let\tikzlastnode\mytikzlastnode]
}},outnorth/.style={append after command={
([yshift=-\pgflinewidth/2]\tikzlastnode.north west) --
([yshift=-\pgflinewidth/2]\tikzlastnode.north east)
pic[midway,sloped,yscale=-1]{inlet}
[/utils/exec=\let\tikzlastnode\mytikzlastnode]
}},insouth/.style={append after command={
([yshift=\pgflinewidth/2]\tikzlastnode.south west) --
([yshift=\pgflinewidth/2]\tikzlastnode.south east)
pic[midway,sloped,yscale=-1]{inlet}
[/utils/exec=\let\tikzlastnode\mytikzlastnode]
}},outsouth/.style={append after command={
([yshift=\pgflinewidth/2]\tikzlastnode.south west) --
([yshift=\pgflinewidth/2]\tikzlastnode.south east)
pic[midway,sloped]{inlet}
[/utils/exec=\let\tikzlastnode\mytikzlastnode]
}},
]
\node[signal,signal from=west, signal to=east,draw,innorth] (one) {one};
\node[signal,signal from=west, signal to=east,draw,below=-\pgflinewidth of one,
innorth] (two) {two};
\node[signal,signal from=west,signal to=none,right=4em of one,draw] (three) {three};
\node[signal,signal from=west, signal to=east,draw,innorth,outsouth,below=2em of two]
(four) {four};
\draw (one.east) -- (three.west);
\end{tikzpicture}
\end{document}