![如何将符号置于节点的中心?](https://linux22.com/image/419256/%E5%A6%82%E4%BD%95%E5%B0%86%E7%AC%A6%E5%8F%B7%E7%BD%AE%E4%BA%8E%E8%8A%82%E7%82%B9%E7%9A%84%E4%B8%AD%E5%BF%83%EF%BC%9F.png)
我想将节点的符号置于中间。我该怎么做?
\documentclass{article}
\usepackage{float}
\usepackage{tikz}
\tikzset{ remember picture,
SYMBOLI/.style = {rectangle,
draw,
semithick,
align=center,
label={below:#1},
label={center:\usebox\SymbolIBox},
minimum size=0.5cm
},
}
\newsavebox\SymbolIBox
\savebox\SymbolIBox{%
\tikz\draw[line width=0.7pt] (-0.15,-0.15)--(-0.05,-0.15)--(0.05,0.15)--(0.15,0.15);%
}
\tikzset{ remember picture,
SYMBOLII/.style = {rectangle,
draw,
semithick,
align=center,
label={below:#1},
label={center:\usebox\SymbolIIBox},
minimum size=0.5cm
},
}
\newsavebox\SymbolIIBox
\savebox\SymbolIIBox{%
\tikz\draw[line width=0.7pt] (-0.15,-0.15)--(-0.15,0.15)--(-0.15,0.05)--(0.15,-0.05)--(0.15,-0.15)--(0.15,0.15);
}
\tikzset{ remember picture,
SYMBOLIII/.style = {rectangle,
draw,
semithick,
align=center,
label={below:#1},
label={center:\usebox\SymbolIIIBox},
minimum size=0.5cm
},
}
\newsavebox\SymbolIIIBox
\savebox\SymbolIIIBox{%
\tikz\draw[line width=0.7pt] (-0.15,0)--(0,0.15)--(0.15,0)--(-0.15,0);%
}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\node[SYMBOLI] {};
\node[SYMBOLII,fill=cyan] at (2,0) {};
\node[SYMBOLIII,fill=magenta] at (4,0) {};
\end{tikzpicture}
\caption{Signs}
\end{figure}
\end{document}
答案1
要使用 TikZ 制作符号,最好使用pic
Till Tantau 为此目的创建的。在手册中,阅读部分Pics: Small Pictures on Paths
。然后,要创建符号,使用起来更容易相对坐标而不是绝对坐标。相对坐标(标有--++
或++
)表示相对于前一点的位移。代码更易读。
\documentclass{article}
%\usepackage[T1]{fontenc}
%\usepackage{graphicx}
\usepackage{float}
\usepackage{tikz}
\tikzset{SYMBOLI/.pic={%
\draw [pic actions,line width=.7pt](-.25,-.25)rectangle(.25,.25);
\draw[line width=0.7pt] (-0.15,-0.15)--++(0.1,0)--++(0.1,0.3)--++(0.1,0);%
}}
\tikzset{SYMBOLII/.pic={%
\draw [pic actions,line width=.7pt](-.25,-.25)rectangle(.25,.25);
\draw[line width=0.7pt] (-0.15,-0.15)--++(0,0.3)++(0,-0.1)--++(0.3,-0.1)++(0,-0.1)--++(0,0.3);
}}
\tikzset{SYMBOLIII/.pic={%
\draw [pic actions,line width=.7pt](-.25,-.25)rectangle(.25,.25);
\draw[line width=0.7pt] (-0.15,-.085)--++(0.15,.15)--++(0.15,-.15)--++(-0.3,0);%
}}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\pic at (0,0) {SYMBOLI};
\pic[fill=cyan] at (2,0) {SYMBOLII};
\pic[fill=magenta] at (4,0) {SYMBOLIII};
\end{tikzpicture}
\caption{Signs}
\end{figure}
\end{document}