![具有多种垂直颜色的椭圆](https://linux22.com/image/362029/%E5%85%B7%E6%9C%89%E5%A4%9A%E7%A7%8D%E5%9E%82%E7%9B%B4%E9%A2%9C%E8%89%B2%E7%9A%84%E6%A4%AD%E5%9C%86.png)
如何为椭圆中的三个独立的垂直部分着色?(例如法国或意大利国旗)。
答案1
像这样吗?
\documentclass[11pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (1.5, 1) ellipse (1.5 and 1);
\clip (1.5, 1) ellipse (1.5 and 1);
\fill[blue] (0,0) rectangle (1, 2);
\fill[white] (1,0) rectangle (2, 2);
\fill[red] (2,0) rectangle (3, 2);
\end{tikzpicture}
\end{document}
答案2
只是为了好玩,国际主义版本如下pstricks
:
\documentclass[x11names, 12pt, border=6pt]{standalone}
\usepackage{graphicx}
\usepackage{pstricks-add}
\usepackage{auto-pst-pdf}
\begin{document}
\psset{plotstyle=curve, linejoin=1}
\sffamily
\begin{pspicture}(-5,-5)(5,5)
\psclip{\psellipse[linestyle=none](0,0)(5,4)}
\rput{90}(0,3){\includegraphics[scale=0.45]{north-korean-flag.eps}}
\endpsclip
\rput[l](-5,-5){\sffamily\bfseries In respectful homage to Kim Jong un}
\end{pspicture}
\end{document}
答案3
您也可以使用\nodepart
。
只是为了爱国:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepgflibrary{shapes.multipart}
\definecolor{verdeb}{RGB}{0,146,70}
\definecolor{biancob}{RGB}{241,242,241}
\definecolor{rossob}{RGB}{206,43,55}
\begin{document}
\begin{tikzpicture}
\draw[thick] ellipse (1.5 and 1);
\clip ellipse (1.5 and 1);
\node [rectangle split, rectangle split parts=3, draw,
rectangle split horizontal,
text width=1cm, minimum height=2.5cm, inner sep=0pt,
rectangle split part fill={verdeb, biancob, rossob}]
{\nodepart{two}\nodepart{three}};
\end{tikzpicture}
\end{document}
答案4
以下是另一个建议path picture
:
\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*\ppverticalfill[3]{
\path[fill=#1]
($(path picture bounding box.south west)!#2!(path picture bounding box.south east)$)
rectangle
($(path picture bounding box.north west)!#3!(path picture bounding box.north east)$)
}
\begin{document}
\begin{tikzpicture}
\draw[
path picture={
\ppverticalfill{blue}{0}{1/3};% first third
\ppverticalfill{yellow}{1/3}{2/3};% second third
\ppverticalfill{red}{2/3}{1};% last third
}
](1.5, 1) ellipse (1.5 and 1);
\end{tikzpicture}
\end{document}
其他例子
\documentclass[margin=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand*\ppverticalfill[3]{
\path[fill=#1]
($(path picture bounding box.south west)!#2!(path picture bounding box.south east)$)
rectangle
($(path picture bounding box.north west)!#3!(path picture bounding box.north east)$)
}
\begin{document}
\begin{tikzpicture}
\draw[
path picture={
\foreach[count=\j] \i in {100,90,...,10}
\ppverticalfill{green!\i!blue}{{(\j-1)/10}}{\j/10};
}
](1.5, 1) ellipse (1.5 and 1);
\end{tikzpicture}
\end{document}