TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am a beginner in LaTeX, and TikZ trying to make an industrial document, with a series of keying patterns. I have managed to produce in the attached MWE what is needed, put I have to adjust manually the position of every half circle into the corresponding hexagon. I wonder if there would be a more sensible way to do this... (ie aligning the center of the half circle with the center of the hexagon). As I have many other configurations to show, where each half circle is to be placed at different angles, I have tried to use a \foreach loop, but could not find a way that would work....I would appreciate any help to improve the code.

\usepackage{tikz} % Enabling watermarks and special graphics
\usetikzlibrary{positioning,chains, matrix,shapes,decorations,backgrounds,}
\begin{tikzpicture}[every node/.style={on grid, regular polygon, regular polygon sides=6,  minimum width=10mm, minimum height=10 mm, draw, very thick, node distance=15mm, anchor= west},]
\node[draw= white, rectangle, text width=18em,  ] (0) {\textbf{Coding pattern for plug}};
\node[right of=0, xshift= 4 em,   label=above:1 ] (1) {}; 
\node [right of=0,  xshift= 4 em,   circle, draw, minimum size=7.8mm] {};
\node [right of=0, xshift= 4 em, yshift =1ex, semicircle, fill= black,  minimum size=3.8mm,] {};
\node[right of=1, label=above:2] (2) {}; 
\node [right of=1,  circle, draw, minimum size=7.8mm] {};
\node [right of=1,  semicircle, fill= black, xshift= 0.9ex, yshift= 0.5ex,  minimum size=3.8mm, rotate=-60] {};
\node [right of=1,  circle, draw, minimum size=7.8mm] {};
\node[right of=2, label=above:3] (3) {};
\node [right of=2,  circle, draw, minimum size=7.8mm] {};
\node [right of=2,  semicircle, fill= black, xshift= 0.7ex, yshift =-0.4ex,  minimum size=3.8mm, rotate=-120] {};
\node[draw= white, rectangle,text width=18em ] (0) {\textbf{Coding pattern for receptacle}};
\node[right of=0, xshift= 4 em,   label=above:4 ] (4) {}; 
\node [right of=0, xshift= 4 em,  yshift=-1ex, semicircle, fill= black,  minimum size=3.8mm, rotate=180] {};
\node [right of=0, xshift= 4 em,  circle, draw, minimum size=7.8mm] {};
\node[right of=4, label=above:3] (3) {}; 
\node [right of=4,  semicircle, fill= black,xshift=-1ex, yshift= -0.5ex, minimum size=3.8mm, rotate=120] {};
\node [right of=4,  circle, draw, minimum size=7.8mm] {};
\node[right of=3, label=above:2] (2) {};
\node [right of=3,  semicircle, fill= black, xshift=-0.7 ex, yshift=0.4ex,minimum size=3.8mm, rotate=60] {};
\node [right of=3,  circle, draw, minimum size=7.8mm] {};

share|improve this question
up vote 2 down vote accepted

I have introduced a new command: \plug[<opt>]{<internal name>}{<rotation>}{<label>}

  • <opt> may be arbitrary TikZ stuff tat get passed to the circle.
    The hexagon will be positioned in the circle's center, as well as the semicircle.
    (Notice anchor=south! This essentially places the south (the middle of the semicircle's diameter) at (c.center).)
  • <internal name> is needed in the positioning of the following plugs.
    But beware, you must use plug<internal name>!
  • <rotation>
  • <label> places a node above the plug. If you (on a user base) want to have a better ability to place these labels, you may replace




    For a one-time override don't use <label> but use the optional argument:

    \plug[…, label={below:5}]{05}{-60}{}


\usepackage{tikz} % Enabling watermarks and special graphics
\usetikzlibrary{positioning,chains, matrix,shapes,decorations,backgrounds}

    \node[draw, very thick, circle,          label={[yshift=1mm]above:#4},    minimum size=7.8mm,                                           #1]                    (plug#2) {};
    \node[draw, very thick, regular polygon, anchor=center,                   minimum width=10mm, minimum height=10mm, regular polygon sides=6] at (plug#2.center)          {};
    \node[draw, very thick, semicircle,      anchor=south,        fill=black, minimum size=3.5mm,                                    rotate=#3] at (plug#2.center)          {};
\begin{tikzpicture}[node distance=15mm]
\node[align=left, text width=18em] (text0) {\textbf{Coding pattern for plug}};
\plug[right of=text0,node distance=40mm]{04}{0}{1}
\plug[right of=plug04]{03}{-60}{2}
\plug[right of=plug03]{02}{-120}{3}

\node[above of=text0, node distance=2cm, align=left, text width=18em] (text1) {\textbf{Coding pattern for receptacle}};
\plug[right of=text1, node distance=40mm]{11}{180}{1}
\plug[right of=plug11]{12}{120}{2}
\plug[right of=plug12]{13}{60}{3}


like so?

share|improve this answer
Thanks. I have removed every node/.style={on grid}, because I did not see a difference after removal. – Yves Sep 30 '12 at 9:09
@Yves I've updated my answer with an explanation and how to use the \plug macro. – Qrrbrbirlbel Sep 30 '12 at 14:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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