我想使用样式“覆盖”(append after command
)制作一个块,它看起来像这样,但带有连接的线段。
有没有办法修改我的代码来实现连接?不幸的是,我真的不知道如何使用\pgfextra
,我修改了另一个我闲置的 .tex 文件,该文件基于我放错位置的 TikZ 示例,所以对我来说这是货物崇拜 TikZ 编程。
\documentclass[border=6mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows,positioning,calc}
\begin{document}
\begin{tikzpicture}[node distance=5mm, auto,
block/.style={
thick,draw=black,
rectangle, minimum size=6mm, minimum width=12mm,
minimum height=10mm, node distance=5mm,
top color=white,
drop shadow
},
satstyle/.style={
append after command={
\pgfextra{\let\lastnode\tikzlastnode}
($(\lastnode.south) + (0,0.3em)$) edge
($(\lastnode.north) + (0,-0.3em)$)
($(\lastnode.west) + (0.3em,0)$) edge
($(\lastnode.east) + (-0.3em,0)$)
($(\lastnode.south west) + (0.5em,0.5em)$) edge[-, very thick]
($(\lastnode.south) + (-0.2em,0.5em)$)
($(\lastnode.south) + (-0.2em,0.5em)$) edge[-, very thick]
($(\lastnode.north) + (0.2em,-0.5em)$)
($(\lastnode.north) + (0.2em,-0.5em)$) edge[-, very thick]
($(\lastnode.north east) + (-0.5em,-0.5em)$)
}
},
>=latex
]
\node (X) [block, satstyle] at (0,0) {};
\end{tikzpicture}
\end{document}
答案1
尝试:
\documentclass[border=6mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows,positioning,calc}
\newcommand\ppbb{path picture bounding box}
\begin{document}
\begin{tikzpicture}[node distance=5mm, auto,
block/.style = {
rectangle, draw, thick, fill=white,
minimum height=9mm, minimum width=12mm,
drop shadow
},
sat/.style = {block,
path picture={
\draw[-latex,thin]
($(\ppbb.south) + (0,0.5ex)$) edge ($(\ppbb.north) + (0,-0.5ex)$)
($(\ppbb.west) + (0.5ex,0)$) to ($(\ppbb.east) + (-0.5ex,0)$);
\draw[very thick]
($(\ppbb.south west) + (1ex,1ex)$) --
($(\ppbb.south) + (-1ex,1ex)$) --
($(\ppbb.north) + (1ex,-1ex)$) --
($(\ppbb.north east) + (-1ex,-1ex)$);
}% end path picture
},
]
\node (X) [sat] {};
\end{tikzpicture}
\end{document}
我稍微重新设计了你的饱和度符号:
绘制边缘时,仅绘制给定坐标之间的线段。
答案2
将 Zarko 的答案改编成我原来的设计,我需要使用\newcommand\ppbb{path picture bounding box}
和
satstyle/.style = {
path picture={
\draw[-, thin]
($(\ppbb.south) + (0,0.3em)$) edge ($(\ppbb.north) + (0,-0.3em)$)
($(\ppbb.west) + (0.3em,0)$) to ($(\ppbb.east) + (-0.3em,0)$);
\draw[very thick]
($(\ppbb.south west) + (0.5em,0.5em)$) --
($(\ppbb.south) + (-0.2em,0.5em)$) --
($(\ppbb.north) + (0.2em,-0.5em)$) --
($(\ppbb.north east) + (-0.5em,-0.5em)$);
}% end path picture
},
完整示例:
\documentclass[border=6mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,shadows,arrows,positioning,calc}
\newcommand\ppbb{path picture bounding box}
\begin{document}
\begin{tikzpicture}[node distance=5mm, auto,
block/.style={
thick,draw=black,
rectangle, minimum size=6mm, minimum width=12mm,
minimum height=10mm, node distance=5mm,
top color=white,
drop shadow
},
satstyle/.style = {
path picture={
\draw[-, thin]
($(\ppbb.south) + (0,0.3em)$) edge ($(\ppbb.north) + (0,-0.3em)$)
($(\ppbb.west) + (0.3em,0)$) to ($(\ppbb.east) + (-0.3em,0)$);
\draw[very thick]
($(\ppbb.south west) + (0.5em,0.5em)$) --
($(\ppbb.south) + (-0.2em,0.5em)$) --
($(\ppbb.north) + (0.2em,-0.5em)$) --
($(\ppbb.north east) + (-0.5em,-0.5em)$);
}% end path picture
},
>=latex
]
\node (X) [block, satstyle] at (0,0) {};
\end{tikzpicture}
\end{document}