1

I want to center the sign for the node in the middle. How do I do it?

enter image description here

\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}
3
  • Do you really need a sledgehammer like TiKZ for that? A simple \fcolorbox can do it. – Bernard Aug 16 '20 at 0:16
  • How would I do it with \fcolorbox? – TheWorker Aug 16 '20 at 8:33
  • Simply, say, \fcolorbox{black}{red}{Symbol}. You might have to add an invisible rule if you want to ensure a square frame (depending on the symbol inside). See §2.6.2, Colored boxes, in the documentation of xcolor. – Bernard Aug 16 '20 at 8:43
3

To make symbols with TikZ, it is preferable to use the pic that have been created by Till Tantau for this purpose. In the manual, read the section Pics: Small Pictures on Paths. Then, to create the symbols, it is easier to use relative coordinates instead of absolute coordinates. Relative coordinates (marked with --++ or ++) indicate the displacement from the previous point. The code is more readable.

screenshot

\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}
7
  • I get an error, "I don't know the key SYMBOLII" and then it ignores it when attempting for symbol2 – TheWorker Aug 16 '20 at 8:50
  • Strange, from my side, there's no error. What engine do you compile with? PdfLaTeX? LaTeX? LuaLaTeX ? Another one? – AndréC Aug 16 '20 at 9:11
  • I am using pdflatex – TheWorker Aug 16 '20 at 9:22
  • It works as a stand alone so it's probably my project which is having issues with the changes – TheWorker Aug 16 '20 at 9:27
  • I am dependent on using this structure \begin{tikzpicture} \node[SYMBOLI] {}; \node[SYMBOLII,fill=cyan] at (2,0) {}; \node[SYMBOLIII,fill=magenta] at (4,0) {}; \end{tikzpicture} – TheWorker Aug 16 '20 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.