9

This question is in connection with Making a family of graphs in TikZ by a few definitions.

In the following MBWE lines in the first diamond, that were expected to be vertical, have unexpected angles. What should I know to correct this behaviour?

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
[inner sep=0.7mm,
koc/.style={circle,draw=black,fill=black,thick,minimum size=3mm},
kob/.style={circle,draw=black,fill=white,thick,minimum size=3mm},
kwc/.style={rectangle,draw=black,fill=black,thick,minimum size=3mm},
kwb/.style={rectangle,draw=black,fill=white,thick,minimum size=3mm},
trc/.style={regular polygon, regular polygon sides=3,draw=black,fill=black,thick, minimum size=1mm},
empty/.style={},
trb/.style={regular polygon, regular polygon sides=3,draw=black,fill=white,thick,minimum size=1mm}]

\node[trc] (A)[label=above:$a$] {};
\node[kob] (D) [above right=of A] {};
\node[empty](empty)[right=of A]{};
\node[kwb] (F) [below right=of  A] {};
\begin{scope}[on grid,node distance=9mm]
\node[kwc] (B) [below=of D,label=above left:$b$] {};
\node[kob] (E) [above=of F] {};
%\node[trc] (F) [below right=of  A] {f};
\end{scope}
\node[trc](C)[right=of empty,label= above:$c$]{};

\foreach \k in {D,B,E,F} \draw(A)--(\k); 
\foreach \k in {D,B,E,F}\draw (\k)--(C);
\draw (D)--(B);
\draw (B)--(E);
\draw (E)--(F);
\end{tikzpicture}
\hspace{1cm}
\begin{tikzpicture}
[inner sep=0.7mm,
koc/.style={circle,draw=black,fill=black,thick,minimum size=3mm},
kob/.style={circle,draw=black,fill=white,thick,minimum size=3mm},
kwc/.style={rectangle,draw=black,fill=black,thick,minimum size=3mm},
kwb/.style={rectangle,draw=black,fill=white,thick,minimum size=3mm},
trc/.style={regular polygon, regular polygon sides=3,draw=black,fill=black,thick, minimum size=1mm},
empty/.style={},
trb/.style={regular polygon, regular polygon sides=3,draw=black,fill=white,thick,minimum size=1mm}]

\node[kwb] (A) {};
\node[kob] (D) [above right=of A] {};
\node[empty](empty)[right=of A]{};
\node[kob] (F) [below right=of  A] {};
\begin{scope}[on grid,node distance=8mm]
\node[trc] (B) [right=of A,label=above right:$a$] {};
\node[kwc] (E) [left=of C,label=above right:$b$] {};
\end{scope}
\node[trc](C)[right=of empty,label=above right:$c$]{};

\foreach \k in {A,B,E,C} \draw(D)--(\k); 
\foreach \k in {A,B,E,C}\draw (\k)--(F);
\draw (A)--(B);
\draw (B)--(E);
\draw (E)--(C);

\end{tikzpicture}
\caption{Case $(\beta,2)$ of Lemma 2.2}
\end{figure}



\end{document}

enter image description here

  • 1
    A hint make the upper circle rectangle ;) – percusse Jun 9 '13 at 19:01
  • @percusse I am afraid that it is not a hint for me. I have noticed that different object give different results, but I cannot see any regularity. – Przemysław Scherwentke Jun 9 '13 at 20:21
  • 1
    @PrzemysławScherwentke The [above|below] [left|right]=… of somenode styles automatically set the reference to somenode.[north|south] [east|west]. While the circles and rectangles have the same dimensions (3mm in width and height), the compass direction south east and so on lie on the circles border and not in the corner of a rectangle enclosing that circle (in TikZ syntax, that would be: (somenode.south -| somenode.east)). – Qrrbrbirlbel Jun 9 '13 at 20:58
4

Here is a different take, using a diamond shape for the four outer nodes, and a path for the two inner nodes. It may be preferable to use either

  • outer sep=+0pt for every node,
  • line cap=rect for the lines, and/or
  • a drawn diamond

so that the lines do not awkwardly end at the nodes’ borders (which is only visible for high zoom levels).

I took the liberty to re-organize the styles.

Code

\documentclass[tikz,convert]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}[
  every whateverthisis/.style={thick, draw=black, inner sep=+0.7mm},
  circle style/.style=  {shape=circle,                                   minimum size=+3mm},
  rect style/.style=    {shape=rectangle,                                minimum size=+3mm},
  triangle style/.style={shape=regular polygon, regular polygon sides=3, minimum size=+1mm},
  black style/.style={fill=black},
  white style/.style={          },
  koc/.style={every whateverthisis, circle style,   black style},
  kob/.style={every whateverthisis, circle style,   white style},
  kwc/.style={every whateverthisis, rect style,     black style},
  kwb/.style={every whateverthisis, rect style,     white style},
  trc/.style={every whateverthisis, triangle style, black style},
  trb/.style={every whateverthisis, triangle style, white style},
]

\node[shape=diamond, minimum size=2.5cm, outer sep=+0pt] (d) {};

\node[trc, label=above:$a$] at (d.west)  (A) {};
\node[trc, label=above:$c$] at (d.east)  (C) {};
\node[kob]                  at (d.north) (D) {};
\node[kwb]                  at (d.south) (F) {};
\path (d.north) -- (d.south) node [pos=.4, kwc, label=above left:$b$] (B) {}
                             node [pos=.6, kob]                       (E) {};

\draw (A) -- (D) -- (C) -- (F) -- (A);
\path (B) edge (A) edge (C) edge (D) edge (E)
      (E) edge (A) edge (C) edge (F);
\end{tikzpicture}
\end{document}

Output

enter image description here

7

One easy way to prevent the problem is to use the on grid option:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
[inner sep=0.7mm,
koc/.style={circle,draw=black,fill=black,thick,minimum size=3mm},
kob/.style={koc,fill=white},
kwc/.style={rectangle,draw=black,fill=black,thick,minimum size=3mm},
kwb/.style={kwc,fill=white},
trc/.style={regular polygon, regular polygon sides=3,draw=black,fill=black,thick, minimum size=1mm},
empty/.style={},
trb/.style={trc,fill=white},on grid,node distance=12mm and 12mm]

\node[trc] (A)[label=above:$a$] {};
\node[kob] (D) [above right=of A] {};
\node[empty](empty)[right=of A]{};
\node[kwb] (F) [below right=of  A] {};
\begin{scope}[on grid,node distance=9mm]
\node[kwc] (B) [below=26pt of D,label=above left:$b$] {};
\node[kob] (E) [above=26pt of F] {};
%\node[trc] (F) [below right=of  A] {f};
\end{scope}
\node[trc](C)[right=of empty,label= above:$c$]{};

\foreach \k in {D,B,E,F} \draw(A)--(\k); 
\foreach \k in {D,B,E,F}\draw (\k)--(C);
\draw (D)--(B);
\draw (B)--(E);
\draw (E)--(F);
\end{tikzpicture}
\caption{Case $(\beta,2)$ of Lemma 2.2}
\end{figure}

\end{document}

enter image description here

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.