TikZ - 两种颜色的圆圈分割

TikZ - 两种颜色的圆圈分割

我需要绘制一个双色的circle split,完全符合 手册第 39.6 节中的规定rectangle splits,这意味着 的一半circle split有一种填充颜色,另一半有另一种填充颜色。我必须在之后旋转它,但这不是问题。

对于矩形分割,似乎只需rectangle split part fill={red, blue}在定义中添加选项即可。对于多色圆形分割,是否有类似的方法?

来自智利的问候,
马塞洛。

答案1

最终代码

修正错误

1)\begin{scope}[on background layer]没有用。

2)\insiderad-0.5\pgflinewidth正确的代码应该是\insiderad-\pgflinewidth

样式circle split part fill需要两种颜色,例如 circle split part fill={blue!50,red!50}

这是一个完整的例子

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,calc}

\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}

\Huge  

\begin{tikzpicture}
  \node[shape=circle split,
    draw=gray!40,
    line width=1mm,text=white,font=\bfseries,
    circle split part fill={blue!50,red!50}
    ] at (5,5) {text\nodepart{lower}lower};
 \end{tikzpicture} 
 \begin{tikzpicture}
 \node[name=s,
    shape=circle split,
    draw=gray!40,
    line width=10mm, minimum width =5cm,
    circle split part fill={blue!50,red!50}
    ] at (5,5) {text\nodepart{lower}lower};
\end{tikzpicture}
\begin{tikzpicture}
\node[name=s,
    shape=circle split,
    draw=gray!40,line width=2mm,
    circle split part fill={blue!50,red!50}
    ] at (5,5) {Big text\nodepart{lower} very big lower};
\end{tikzpicture} 
\end{document} 

在此处输入图片描述

解决方法(第一个想法):

\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,calc}

\begin{document}

\Huge
\begin{tikzpicture}
  \node[name=s,shape=circle split,draw=gray!40,line width=4mm,minimum size=8cm] {text\nodepart{lower}lower};
  \foreach \anchor/\placement in
    {north west/above left, north/above, north east/above right,
     west/left, center/below, east/right,
     mid west/right, mid/above, mid east/left,
     base west/left, base/below, base east/right,
     south west/below left, south/below, south east/below right,
     text/left, lower/left, 130/above}
     \draw[shift=(s.\anchor)] plot[mark=x] coordinates{(0,0)}
       node[\placement] {\scriptsize\texttt{(s.\anchor)}}; 

\begin{scope}[on background layer]
    \fill[blue!50] (s.base) ([xshift=-4mm]s.east) arc (0:180:4cm-2mm)--cycle;
    \fill[red!50] (s.base) ([xshift=4mm]s.west) arc (180:360:4cm-2mm)--cycle;  
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

从此代码中创建样式并不容易。最终它成为可能!

相关内容