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

4
  • have a look athe answer below – js bibra Feb 23 at 5:52
  • is there something else required -- would you like to accept the answer – js bibra Feb 23 at 7:17
  • is there something else required -- would you like to accept the answer – js bibra Feb 23 at 7:17
  • @jsbibra This is exactly what I was looking for, thanks! – DurandA Feb 23 at 11:03
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.