如何使用 TikZ 以不同的比例用两种颜色填充形状?

如何使用 TikZ 以不同的比例用两种颜色填充形状?

我想用两种水平分布的颜色填充 TikZ 形状/节点,并能够调整它们之间的比例,如下所示(类似于加载栏):

TikZ 颜色色调

我尝试修改这个例子使用阴影,但渲染不同,并且总是产生一些颜色混合:

颜色阴影示例

答案1

在此处输入图片描述

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows,shadings,shapes.symbols, calc}

\begin{document}
    \begin{tikzpicture}[my node/.style={draw, cloud, cloud ignores aspect, }]
         \node[my node] (a1)  {Text};

    \end{tikzpicture}

\begin{tikzpicture}[fill fraction/.style n args={2}{path picture={
            \fill[#1] (path picture bounding box.south west) rectangle
            ($(path picture bounding box.north west)!#2!(path picture bounding box.north east)$);}}]
        
    \draw (4, 0) node[cloud, cloud ignores aspect,draw,fill=blue, fill fraction={green}{0.7}] {Some
        other text};
\end{tikzpicture}
\end{document}

编辑

长文本破坏了云的形状,因此需要编辑

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{shadows,shadings,shapes.symbols, calc}

\begin{document}
    \begin{tikzpicture}[my node/.style={draw, cloud, cloud ignores aspect, }]
         \node[my node] (a1)  {Text};

    \end{tikzpicture}

\begin{tikzpicture}[fill fraction/.style n args={2}{path picture={
            \fill[#1] (path picture bounding box.south west) rectangle
            ($(path picture bounding box.north west)!#2!(path picture bounding box.north east)$);}}]
        
    \draw (4, 0) node[cloud, cloud ignores aspect,draw,fill=blue, fill fraction={green}{0.7}] {text};
\end{tikzpicture}
\end{document}

结果是

在此处输入图片描述

相关内容