我正在尝试定义一些节点,其中将包含矩形节点内的标准符号:
\tikzset{ remember picture,
SYMBOL/.style = {rectangle,
line width=1pt,
draw,align=center,
label={below:#1},
},
}
这应该在节点文本内:
\draw[line width=0.7pt] (-0.2,-0.2)--(-0.05,-0.2)--(0.05,0.2)--(0.2,0.2)
(-0.2,0)--(0.2,0);
我怎样才能做到这一点?
答案1
您可以将符号装箱,然后在\node
文本内使用该框;将符号装箱将防止其继承包含的不需要的设置tikzpicture
;如果不需要这样做,\newcommand
则可以使用简单的方法:
\documentclass{article}
\usepackage{tikz}
\tikzset{ remember picture,
SYMBOL/.style = {rectangle,
line width=1pt,
draw,align=center,
label={below:#1},
},
}
\newsavebox\mybox
\savebox\mybox{%
\tikz\draw[line width=0.7pt] (-0.2,-0.2)--(-0.05,-0.2)--(0.05,0.2)--(0.2,0.2)
(-0.2,0)--(0.2,0);%
}
\begin{document}
\begin{tikzpicture}
\node[SYMBOL=text] {\usebox\mybox};
\node[SYMBOL=text,fill=cyan] at (2,0) {\usebox\mybox};
\end{tikzpicture}
\end{document}
如果每个 SYMBOL 节点都应包含给定的符号,那么您可以执行以下操作:
\documentclass{article}
\usepackage{tikz}
\tikzset{ remember picture,
SYMBOL/.style = {rectangle,
line width=1pt,
draw,
align=center,
label={below:#1},
label={center:\usebox\mybox},
minimum size=20pt
},
}
\newsavebox\mybox
\savebox\mybox{%
\tikz\draw[line width=0.7pt] (-0.2,-0.2)--(-0.05,-0.2)--(0.05,0.2)--(0.2,0.2)
(-0.2,0)--(0.2,0);%
}
\begin{document}
\begin{tikzpicture}
\node[SYMBOL=text] {};
\node[SYMBOL=text,fill=cyan] at (2,0) {};
\end{tikzpicture}
\end{document}