我有以下示例,我想知道为什么它不起作用:
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{quotes}
\usetikzlibrary{shadows}
\RequirePackage{luatex85}
\begin{document}
\newcommand\unit{1.2cm}
\begin{tikzpicture}[
pics/limiter/.style={
code={
\draw[black!50,very thin] (-0.45*\unit,0) -- (0.45*\unit,0);
\draw[black!50,very thin] (0,-0.45*\unit) -- (0,0.45*\unit);
\draw (0.5*\unit,0.5*\unit) -- (0.5*\unit,-0.5*\unit) --
(-0.5*\unit,-0.5*\unit) -- (-0.5*\unit,0.5*\unit) -- cycle;
\draw (-0.4*\unit,-0.4*\unit) -- (-0.25*\unit,-0.4*\unit) --
(0.25*\unit,0.4*\unit) -- (0.4*\unit,0.4*\unit);
\coordinate (-north) at (0,0.5*\unit);
\coordinate (-west) at (-0.5*\unit,0);
\coordinate (-south) at (0,-0.5*\unit);
\coordinate (-east) at (0.5*\unit,0);
},
drop shadow={shadow xshift=.3ex,shadow yshift=-.3ex}
}
]
\pic[fill=yellow!50] (lim) at(0,0) {limiter};
\end{tikzpicture}
\end{document}
只有阴影才看起来像这样
答案1
使用标准节点绘制限制器更简单、更灵活(关于节点名称、定位等)。除此之外,\pic
似乎无法使用drop shadow
路径选项。
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows}
\begin{document}
\newcommand\unit{1.2cm}
\begin{tikzpicture}[
limiter/.style = {shape=rectangle, draw,
fill=#1, drop shadow,
minimum size=\unit, outer sep=0mm,
path picture={%
\draw[black!50,very thin] (-0.45*\unit,0) -- (0.45*\unit,0);
\draw[black!50,very thin] (0,-0.45*\unit) -- (0,0.45*\unit);
\draw (-0.40*\unit,-0.4*\unit) -- (-0.25*\unit,-0.4*\unit) --
( 0.25*\unit, 0.4*\unit) -- ( 0.40*\unit, 0.4*\unit);
},% end path picture
},% end of limiter
limiter/.default = white
]
\node[limiter] (lim) at (0,0) {};
\node[limiter=yellow] (lim) at (2,0) {};
\end{tikzpicture}
\end{document}