我可以使用以下代码轻松绘制椭圆:
\documentclass[tikz, margin=5pt]{standalone}
\usetikzlibrary{shapes,positioning}
\begin{document}
\begin{tikzpicture}
\tikzset{
elps/.style 2 args={draw, ellipse,minimum width=#1, minimum height=#2},
node distance=3 cm,
font=\footnotesize,
>=latex,
bullet/.style = {circle, inner sep=1pt, fill}}
\node(a)[elps={2cm}{3cm}, label={below:$A$}]{};
\end{tikzpicture}
\end{document}
怎样才能在不完全改变(如果可能的话)我的实际代码的情况下实现如图所示的结果?
答案1
以下是使用的建议path picture
:
\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}
\newcommand\ppfill[2]{%
\foreach \c/\dir in {#1/{north },#2/{south }}
\path[fill=\c,draw]
(path picture bounding box.\dir west)--
(path picture bounding box.west)to[out=-60,in=210]
(path picture bounding box.center)to[out=30,in=120]
(path picture bounding box.east)--
(path picture bounding box.\dir east)--cycle
;
}
\begin{document}
\begin{tikzpicture}
\tikzset{
elps/.style 2 args={draw, ellipse,minimum width=#1, minimum height=#2},
node distance=3 cm,
font=\footnotesize,
>=latex,
bullet/.style = {circle, inner sep=1pt, fill}
}
\node(a)[elps={2cm}{3cm},label={below:$A$}]
[path picture=\ppfill{red}{green}]{};
\node(b)[elps={5cm}{3cm},label={below:$B$}]
[right=1cm of a,draw=orange,line width=1mm]
[path picture=\ppfill{green}{blue}]{};
\end{tikzpicture}
\end{document}
结果: