1

I want to fill a TikZ shape/node with two colors that are spitted horizontally and be able to adjust the ratio between them like as follows (similar to a loading bar):

TikZ color shade

I tried to modify this example that uses shading but the rendering is different and always produces some color mixing:

color shading example

DurandA
  • 176

1 Answers1

3

enter image description here

\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}

EDIT

The long text spoils the shape of the cloud so an edit

\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}

results in

enter image description here

js bibra
  • 21,280