具有多种垂直颜色的椭圆

具有多种垂直颜色的椭圆

如何为椭圆中的三个独立的垂直部分着色?(例如法国或意大利国旗)。

答案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}

在此处输入图片描述

相关内容