以下是源代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0, 0) circle (1cm);
\path[fill=black] (90:1cm) arc (90:270:1cm);
\path[fill=black] (0:0cm) arc (-90:90:.5cm);
\path[fill=white] (0:0cm) arc (90:270:.5cm);
\path[fill=white] (0, .5) circle (.1cm);
\path[fill=black] (0, -.5) circle (.1cm);
\end{tikzpicture}
\begin{tikzpicture}
\draw (0, 0) circle (1cm);
\filldraw[color=black] (90:1cm) arc (90:270:1cm);
\fill[color=black] (0, .5) circle (.5cm);
\fill[color=white] (0, -.5) circle (.5cm);
\fill[color=white] (0, .5) circle (.1cm);
\fill[color=black] (0, -.5) circle (.1cm);
\end{tikzpicture}
\end{document}
两种方法都应该可行,但显然第一种方法存在一些缺陷,为什么?
答案1
虽然这可能是舍入错误,但它仍然很烦人。这也是您构造符号的方式造成的,因为您绘制并填充了一个半圆。相反,您可以做一些类似的事情:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0, 0) circle (1cm);
\path[fill=black] (90:1cm) arc (90:-90:0.5cm)
(0,0) arc (90:270:0.5cm)
(0,-1cm) arc (-90:-270:1cm);
\path[fill=white] (0, 0.5) circle (0.1cm);
\path[fill=black] (0,-0.5) circle (0.1cm);
\end{tikzpicture}
\end{document}
答案2
或者,您可以通过一条路径执行此操作:
代码
\documentclass[tikz]{standalone}
\tikzset{
YinYang/.style={insert path={{[even odd rule, start angle=90, delta angle=180]
coordinate (@aux) circle [radius={#1}]
arc [radius={(#1)/2}]
arc [radius={#1}, start angle=270]
arc [radius={(#1)/2}, delta angle=-180]
([shift=(down:{(#1)/2})] @aux) circle [radius={(#1)/10}]
([shift=( up:{(#1)/2})] @aux) circle [radius={(#1)/10}]
% doing the big circle as an edge allows us to only draw that and only fill the rest
(@aux) edge[to path={circle [radius={#1}]}] ()}}}}
\begin{document}
\tikz\fill[YinYang=1];
\tikz\fill[
draw=white, every edge/.style,
even odd rule, inner color=red, outer color=blue,
preaction ={inner color=blue, outer color=red },
% the preaction uses nonzero rule, so it is essentially only the full circle.
] [YinYang=-1];% negative raduius flips the two halves
\end{document}