我正在尝试剪切标准矩形的底部和顶部线条。我现在得到的是一个如下所示的矩形:
其结果是:
\node [rectangle,draw=black,rounded corners=30pt,dashed] {Test123};
我想要的结果应该是这样的:
我不知何故无法相信没有更好的解决方案,而不是用另一条白线覆盖顶部和底部的线(这会因为更多的矩形而变得非常混乱,就像在我的情况下一样)。
如果解决方案具有以下特性,那就太好了:
- 可以轻松嵌入/添加/附加文本
- 可以从该对象的锚点绘制线条
- 可以轻松移动(作为整个物体)
由于我不是 tikz 专业人士,如果上述属性是 tikz 中绘图/对象的标准功能,我深感抱歉。
答案1
一种选项是使用样式并将append after command
虚线添加到节点;由于该解决方案使用,\path ... node ...;
您可以在节点上执行所有操作(使用标准可用键,命名它们并访问它们的锚点来绘制元素):
\documentclass{article}
\usepackage{tikz}
\tikzset{
keep name/.style={
prefix after command={
\pgfextra{\let\fixname\tikzlastnode}
}
},
partialbox/.style={
keep name,
append after command={
([xshift=#1]\fixname.north west) --
(\fixname.north west) --
(\fixname.south west) --
([xshift=#1]\fixname.south west)
([xshift=-#1]\fixname.north east) --
(\fixname.north east) --
(\fixname.south east) --
([xshift=-#1]\fixname.south east)
}
},
partialbox/.default=15pt
}
\begin{document}
\begin{tikzpicture}
\path[draw,rounded corners,dashed]
node[partialbox,minimum height=30pt,align=center]
{Some test text};
\path[draw,rounded corners=20pt,dashed]
node[partialbox,minimum height=50pt,align=center,fill=red!20]
at (4,0)
(A)
{Some test text};
\path[draw,rounded corners=20pt,dashed]
node[partialbox=30pt,minimum height=70pt,fill=cyan!20]
at (8,0)
(B)
{Some test text};
\path[draw,rounded corners=20pt,dotted]
node[partialbox,minimum height=70pt]
at (0,-4)
{Some test text};
\path[draw=red!80!black,line width=1pt,rounded corners=20pt,densely dashed]
node[partialbox=20pt,minimum height=40pt,align=center,inner sep=20pt]
at (4,-4)
(C)
{Some \\ additional test text \\ and some more};
\draw[-latex]
(A.south) -- ++(0pt,-25pt) -| (B.south);
\draw[latex-latex]
(B.east) -- ++(10pt,0pt) |- (C.east);
\end{tikzpicture}
\end{document}