我有以下 tikz 风格
\tikzset{actor/.style={ rectangle, minimum size=6mm, very thick,
draw=red!50!black!50, top color=white, bottom
color=red!50!black!20 }
}
我想要另一种样式,与上面相同,但矩形中有一个叉号。我该如何实现?
答案1
您可以append after command
与库结合使用fit
,将cross out
节点(来自shapes.misc
库)放置在actor
节点上方:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.misc, fit}
\begin{document}
\begin{tikzpicture}
\tikzset{
actor/.style={
rectangle, minimum size=6mm, very thick,
draw=red!50!black!50, top color=white, bottom
color=red!50!black!20
},
actor crossed out/.style={
actor,
append after command={
node [
fit=(\tikzlastnode),
draw=red!50!black!50,
thick,
inner sep=-\pgflinewidth,
cross out
] {}
}
}
}
\node [actor] (a) {A};
\node [actor crossed out, right of = a] {B};
\end{tikzpicture}
\end{document}
或者,您可以使用edge
中的 s 来append after command
绘制线条。这不需要任何库:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzset{
actor/.style={
rectangle, minimum size=6mm, very thick,
draw=red!50!black!50, top color=white, bottom
color=red!50!black!20
},
actor crossed out/.style={
actor,
append after command={
[every edge/.append style={
thick,
red!50!black!50,
shorten >=\pgflinewidth,
shorten <=\pgflinewidth,
}]
(\tikzlastnode.north west) edge (\tikzlastnode.south east)
(\tikzlastnode.north east) edge (\tikzlastnode.south west)
}
}
}
\node [actor] (a) {A};
\node [actor crossed out, right of = a] {B};
\end{tikzpicture}
\end{document}