我正在尝试绘制一些带有黑色边缘和白色表面颜色的圆圈。这些圆圈位于椭圆的边缘。我不明白为什么此代码不起作用:
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\shadedraw [inner color=black!10,outer color=black!60,domain=0:2*pi] plot ({2*cos(\x r)},{1*sin(\x r)});
\foreach \a in {0,0.6283,...,6.2832}
{
% I was expecting circles with a black edge
\fill [black,fill=white] ({2*cos(\a r)},{1*sin(\a r)}) circle (4pt);
}
\end{tikzpicture}
\end{document}
这是我得到的(圆圈边缘要么是白色的,要么根本没有画出来):
谢谢!
答案1
使用draw=black
或\filldraw
。正如 Grimler 所说,\fill
颜色仅用作填充颜色。您没有告诉 TikZ 绘制形状,只是填充它,并且填充颜色设置为白色。通过添加,draw=black
形状也会使用指定的颜色绘制。\filldraw[black,fill=white]
形状的轮廓用黑色绘制,并用白色填充。(实际上,顺序是先填充,然后绘制。)
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\shadedraw [inner color=black!10,outer color=black!60,domain=0:2*pi] plot ({2*cos(\x r)},{1*sin(\x r)});
\foreach \a in {0,0.6283,...,6.2832}
{
% \filldraw [black,fill=white] ({2*cos(\a r)},{1*sin(\a r)}) circle (4pt);
\fill [draw=black,fill=white] ({2*cos(\a r)},{1*sin(\a r)}) circle (4pt);
}
\end{tikzpicture}
\end{document}
答案2
或者使用\filldraw
。也许您想剪辑更多,samples
以便获得更平滑的椭圆。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[,line width=1.4\pgflinewidth]
\clip [domain=0:2*pi,samples=500] plot ({2*cos(\x r)},{1*sin(\x r)});
\shadedraw [inner color=black!10,outer color=black!60,domain=0:2*pi,samples=500] plot ({2*cos(\x r)},{1*sin(\x r)});
\foreach \a in {0,0.6283,...,6.2832}
{
% I was expecting circles with a black edge
\filldraw [black,fill=white,line width=0.7\pgflinewidth] ({2*cos(\a r)},{1*sin(\a r)}) circle (4pt);
}
\end{tikzpicture}
\end{document}