如何将符号置于节点的中心?

如何将符号置于节点的中心?

我想将节点的符号置于中间。我该怎么做?

在此处输入图片描述

\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 制作符号,最好使用picTill 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}

相关内容