4

Using an idea posted here I'd like to draw a graph of vertices and edges using some split circular nodes (and colored differently). Unfortunately the edges are not ending nicely.

It would also be lovely if I could set teh minimum node size to 6mm instead of my hack for each vertex.

Is there anything that anybody could suggest?

Here's my MWE:

\documentclass{beamer}

\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,calc}


% https://tex.stackexchange.com/questions/55594/tikz-two-colored-circle-split
\makeatletter
\tikzset{circle split part fill/.style args={#1,#2}{%
 alias=tmp@name, % Jake's idea !!
  postaction={%
    insert path={
     \pgfextra{% 
     \pgfpointdiff{\pgfpointanchor{\pgf@node@name}{center}}%
                  {\pgfpointanchor{\pgf@node@name}{east}}%            
     \pgfmathsetmacro\insiderad{\pgf@x}
      %\begin{scope}[on background layer]
      %\fill[#1] (\pgf@node@name.base) ([xshift=-\pgflinewidth]\pgf@node@name.east) arc
      %                    (0:180:\insiderad-0.5\pgflinewidth)--cycle;
      %\fill[#2] (\pgf@node@name.base) ([xshift=\pgflinewidth]\pgf@node@name.west)  arc
      %                     (180:360:\insiderad-0.5\pgflinewidth)--cycle;  
      \fill[#1] (\pgf@node@name.base) ([xshift=-\pgflinewidth]\pgf@node@name.east) arc
                          (0:180:\insiderad-\pgflinewidth)--cycle;
      \fill[#2] (\pgf@node@name.base) ([xshift=\pgflinewidth]\pgf@node@name.west)  arc
                           (180:360:\insiderad-\pgflinewidth)--cycle;            %  \end{scope}   
         }}}}}  
 \makeatother  

\begin{document}

\begin{tikzpicture}
  \tikzset{every node}{minimum size=8mm}
  \node[circle split part fill={red,cyan}] (p1) at (  0:1.9) {\,\,\,\,}; 
  \node[circle split part fill={blue,magenta}] (p2) at ( 72:1.9) {\,\,\,\,};
  \node[circle split part fill={green,violet}] (p3) at (144:1.9) {\,\,\,\,};
  \node[circle split part fill={green,violet}] (p4) at (216:1.9) {\,\,\,\,};
  \node[circle split part fill={orange,pink}] (p5) at (288:1.9) {\,\,\,\,};

  \draw (p1) -- (p2);
  \draw (p1) -- (p3);
  \draw (p1) -- (p4);
  \draw (p1) -- (p5);
  \draw (p2) -- (p3);
  \draw (p2) -- (p4);
  \draw (p2) -- (p5);
  \draw (p3) -- (p5);
\end{tikzpicture}
\end{document}

Many thanks.

4

You need to add shape=circle split when creating the nodes so that the shape and its anchors are constructed correctly. Then the edges connect nicely because the appropriate anchors exist.

\documentclass[tikz,border=5pt]{standalone}

\usetikzlibrary{shapes}


% http://tex.stackexchange.com/questions/55594/tikz-two-colored-circle-split
\makeatletter
\tikzset{circle split part fill/.style args={#1,#2}{%
 alias=tmp@name, % Jake's idea !!
  postaction={%
    insert path={
     \pgfextra{%
     \pgfpointdiff{\pgfpointanchor{\pgf@node@name}{center}}%
                  {\pgfpointanchor{\pgf@node@name}{east}}%
     \pgfmathsetmacro\insiderad{\pgf@x}
      %\begin{scope}[on background layer]
      %\fill[#1] (\pgf@node@name.base) ([xshift=-\pgflinewidth]\pgf@node@name.east) arc
      %                    (0:180:\insiderad-0.5\pgflinewidth)--cycle;
      %\fill[#2] (\pgf@node@name.base) ([xshift=\pgflinewidth]\pgf@node@name.west)  arc
      %                     (180:360:\insiderad-0.5\pgflinewidth)--cycle;
      \fill[#1] (\pgf@node@name.base) ([xshift=-\pgflinewidth]\pgf@node@name.east) arc
                          (0:180:\insiderad-\pgflinewidth)--cycle;
      \fill[#2] (\pgf@node@name.base) ([xshift=\pgflinewidth]\pgf@node@name.west)  arc
                           (180:360:\insiderad-\pgflinewidth)--cycle;            %  \end{scope}
         }}}}}
 \makeatother

\begin{document}

\begin{tikzpicture}
  [every node/.style={minimum size=8mm}]
  \node[shape=circle split,circle split part fill={red,cyan}] (p1) at (  0:1.9) {\,\,\,\,};
  \node[shape=circle split,circle split part fill={blue,magenta}] (p2) at ( 72:1.9) {\,\,\,\,};
  \node[shape=circle split,circle split part fill={green,violet}] (p3) at (144:1.9) {\,\,\,\,};
  \node[shape=circle split,circle split part fill={green,violet}] (p4) at (216:1.9) {\,\,\,\,};
  \node[shape=circle split,circle split part fill={orange,pink}] (p5) at (288:1.9) {\,\,\,\,};

  \draw (p1) -- (p2);
  \draw (p1) -- (p3);
  \draw (p1) -- (p4);
  \draw (p1) -- (p5);
  \draw (p2) -- (p3);
  \draw (p2) -- (p4);
  \draw (p2) -- (p5);
  \draw (p3) -- (p5);
\end{tikzpicture}
\end{document}

nice edges

EDIT

Correct syntax for specifying the minimum size of nodes. This can be specified as an option to tikzpicture as shown, as an option for a scope or on a per node basis.

  • That does the job perfectly. Thanks. For my own edification how can I set the minimum node size to, say, 8mm? My "\,\,\,\," hack is inelegant, to say the least. – healyp Jul 4 '15 at 10:19
  • @healyp Glad it helps. See edit. Is this what you wanted? – cfr Jul 4 '15 at 12:39
  • Yes, that's it. Thanks. So [every node/.style={minimum size=8mm}] works but (from my MWE) \tikzset{every node}{minimum size=8mm} doesn't. But perhaps my other problem in my MWE prevented the \tikzset{} from taking effect. Thanks again. – healyp Jul 4 '15 at 14:20
  • @healyp No, the syntax of \tikzset is wrong anyway. You'd need \tikzset{every node/.style={minimum size=8mm}}. \tikzset{} takes only one argument (but the argument may be a comma separated list). E.g. \tikzset{every node/.style={minimum size=8mm}, line width=1pt, draw=blue} etc. – cfr Jul 4 '15 at 16:35

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.