TIKZ: only fill 75% of the node-background with color

I want to use some background color on my node, but not for the whole node. Just for 75% of the node.

My code is this:

\documentclass[tikz,margin=5mm]{standalone}
\begin{document}
\tikz\node[draw, fill=gray!30]{Some Text};
\end{document}


Which produces this:

But I want more something like this:

Edit: The white and the grey part should be reversed in the second image.

You can use path picture and path picture bounding box:

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\tikz
\node[draw]
[path picture={
\fill[gray!30](path picture bounding box.north west)rectangle
($(path picture bounding box.north east)!.75!(path picture bounding box.south east)$);
}](n)
{Some Text}
;
\end{document}


This works also if the node is a circle:

or a cloud (options: cloud,cloud ignores aspect, needs library shapes.symbols):

Only if the node is a rectangle, you can use the node name instead path picture bounding box:

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\tikz
\node[draw]
[path picture={
\fill[gray!30](n.north west)rectangle($(n.north east)!.75!(n.south east)$);
}](n)
{Some Text}
;
\end{document}


Update (because of a comment)

If the background should be colored in an intervall, eg. from 0.3 to 0.8, use

($(<name>.north west)!.3!(<name>.south west)$)
rectangle
($(<name>.north east)!.8!(<name>.south east)$);


Replace <name> by the node name or path picture bounding box.

Code:

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\tikz
\node[draw]
[path picture={
\fill[gray!30]
($(path picture bounding box.north west)!.3!(path picture bounding box.south west)$)
rectangle
($(path picture bounding box.north east)!.8!(path picture bounding box.south east)$);
}](n)
{Some Text}
;
\end{document}

• Thanks for the answer, thats it! How can i define an specific intervall? i.e. 'just color the background from 0.8 till 0.3 gray' May 10 '17 at 5:11
• @ipo See the example at the end of my updated answer.
– esdd
May 10 '17 at 8:38

Doing the fill in a separate step might be an option.

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc,backgrounds,scopes}
\begin{document}
\begin{tikzpicture}
\node[draw] (a) {Some Text};
{ [on background layer]
\fill[gray!30] (a.north west) rectangle ($(a.south east)!0.3!(a.north east)$);
}
\end{tikzpicture}
\end{document}

• Oops, that 0.3 should of course be 0.25. May 9 '17 at 16:29

I propose something similar: shading

\documentclass[tikz,margin=5mm]{standalone}
\begin{document}
\tikz\node[draw, top color=gray!30,bottom color=white]{Some Text};
\end{document}


EDIT

Since it was requested, here is a sample with a fading; I set the background as orange, in order to make the effect apparent

\documentclass{article}
\usepackage{pagecolor}
\usepackage{tikz}
\pagecolor{yellow!30!orange}
\begin{document}


• Is there also a way to make the color transparent? And i don't mean white. i.e. top color=white!30,bottom color=none May 9 '17 at 18:39