编辑

编辑

使用已发布的想法这里我想使用一些分割的圆形节点(并使用不同的颜色)绘制顶点和边的图形。不幸的是,这些边的结尾不太好看。

如果我可以将最小节点大小设置为 6 毫米而不是对每个顶点进行修改,那就太好了。

有人能建议什么吗?

这是我的 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@[email protected]) ([xshift=-\pgflinewidth]\pgf@[email protected]) arc
      %                    (0:180:\insiderad-0.5\pgflinewidth)--cycle;
      %\fill[#2] (\pgf@[email protected]) ([xshift=\pgflinewidth]\pgf@[email protected])  arc
      %                     (180:360:\insiderad-0.5\pgflinewidth)--cycle;  
      \fill[#1] (\pgf@[email protected]) ([xshift=-\pgflinewidth]\pgf@[email protected]) arc
                          (0:180:\insiderad-\pgflinewidth)--cycle;
      \fill[#2] (\pgf@[email protected]) ([xshift=\pgflinewidth]\pgf@[email protected])  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}

非常感谢。

答案1

您需要shape=circle split在创建节点时添加,以便正确构建形状及其锚点。然后,由于存在适当的锚点,边缘可以很好地连接。

\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@[email protected]) ([xshift=-\pgflinewidth]\pgf@[email protected]) arc
      %                    (0:180:\insiderad-0.5\pgflinewidth)--cycle;
      %\fill[#2] (\pgf@[email protected]) ([xshift=\pgflinewidth]\pgf@[email protected])  arc
      %                     (180:360:\insiderad-0.5\pgflinewidth)--cycle;
      \fill[#1] (\pgf@[email protected]) ([xshift=-\pgflinewidth]\pgf@[email protected]) arc
                          (0:180:\insiderad-\pgflinewidth)--cycle;
      \fill[#2] (\pgf@[email protected]) ([xshift=\pgflinewidth]\pgf@[email protected])  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}

漂亮的边缘

编辑

指定节点最小大小的正确语法。这可以作为选项指定(tikzpicture如图所示)、作为范围选项或基于每个节点指定。

相关内容